开发者

Apache: apply rules to a URL before they're rewritten

开发者 https://www.devze.com 2023-01-31 08:15 出处:网络
I have a simple RewriteRule: RewriteRule ^/r/[0-9]+/(.*)$ /$1 This is used for cache-busting. With every web site release I change the url prefix, e.g.:

I have a simple RewriteRule:

RewriteRule ^/r/[0-9]+/(.*)$ /$1

This is used for cache-busting. With every web site release I change the url prefix, e.g.:

/r/17/img/image.jpg gets /img/image.jpg.

I want to apply long expiry headers to these for example

<Directory /r>
  Header unset ETag
  FileETag None
  ExpiresDefault "access plus 1 year"
</Directory>

Of开发者_StackOverflow中文版 course this doesn't work because after the RewriteRule is applied, the Directory doesn't match anymore. How can I apply these rules inside the Directory directive to URLs accessed via /r/ ?

Thanks!


The <Directory> directive is for actual existing directories and not just URL paths. Try <LocationMatch> instead:

<LocationMatch "^/r(/|$)">
  Header unset ETag
  FileETag None
  ExpiresDefault "access plus 1 year"
</LocationMatch>

Or change /r to your actual directory /img.

0

精彩评论

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