开发者

Apache with mod_rewrite in use and FilesMatch

开发者 https://www.devze.com 2023-02-02 18:09 出处:网络
In my .htaccess file I have: <FilesMatch \"\\.(js|css|png|gif|jpg)$\"> <IfModule mod_headers.c>

In my .htaccess file I have:

<FilesMatch "\.(js|css|png|gif|jpg)$">
<IfModule mod_headers.c>
Header set Cache-Control "public, max-age=3153600开发者_运维百科0"
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?


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");


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>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号