skeggse
skeggse

Reputation: 6323

Apache with mod_rewrite in use and FilesMatch

In my .htaccess file I have:

<FilesMatch "\.(js|css|png|gif|jpg)$">
<IfModule mod_headers.c>
Header set Cache-Control "public, max-age=31536000"
Header set Expires "A31536000"
</IfModule>
</FilesMatch>

I also have a rewrite for /forum-js/forum.js -> /wp-content/plugins/forum/js/forum.js.php, this is the only file that should match the above regex. For some reason, all other resources matching that regex have headers that include Cache-Control and Expires, but this one does not. Is it because it's a rewritten url?

Upvotes: 0

Views: 2909

Answers (2)

Gumbo
Gumbo

Reputation: 655319

You could also use mod_expires instead:

<IfModule mod_expires.c>
    <FilesMatch "\.(js|css|png|gif|jpg)$">
        ExpiresDefault A31536000
    </FilesMatch>
</IfModule>

It also works with MIME media types instead of file name extensions:

<IfModule mod_expires.c>
    ExpiresByType application/javascript A31536000
    ExpiresByType text/css A31536000
    ExpiresByType image/png A31536000
    ExpiresByType image/gif A31536000
    ExpiresByType image/jpeg A31536000
</IfModule>

Upvotes: 2

Pekka
Pekka

Reputation: 449485

Is it because it's a rewritten url?

Yup, as per your comment, its real extension is .php and the rules associated with that extension are in effect.

The easiest thing would be to send the headers from within the PHP script:

<? header("Cache-Control: public, max-age=31536000");
   header("Expires : pA31536000");

Upvotes: 3

Related Questions