My rewrite rule is working and redirecting requests like /versioned/1234/images/foo.gif to /images/foo.gif but it doesn't seem to be setting the set_expires_header environment variable because the headers are not being appended. If I uncomment the line that explicitly sets the environment variable then the headers are set. What am I doing wrong? Is there a better way to do this? I want to be able to access the files with both URLs but only have the headers added when accessing it through the versioned URL.
<VirtualHost *:80>
ServerName dev.example.com
DocumentRoot /var/www/html/dev
<Directory "/var/www/html/dev">
Options FollowSymLinks ExecCGI
AllowOverride All
Order allow,deny
Allow from all
SetEnvIf Request_URI versioned set_expires_header
RewriteEngine on
RewriteRule ^versioned/[^/\.]+/(.*)$ /$1 [E=set_expires_header:true,L]
#SetEnv set_expires_header true
Header append Expires "access plus 1 year" env=set_expires_header
Header append Cache-Control "public" env=set_expires_header
</Directory>
</VirtualHost>