首页 > 解决方案 > RewriteCond 获取主页的 THE_REQUEST

问题描述

我有这些指令.htaccess不缓存某些网址的页面:

<IfModule mod_headers.c>
    RewriteCond %{THE_REQUEST} (compile|chat|another-page) [NC]
    RewriteRule ^ - [NC,E=HEADER_NOCACHE:true]
    Header unset ETag
    Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
    Header set Pragma "no-cache"
    Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
</IfModule>

它就像页面的魅力一样h..ps://my-url/compileh..ps://my-url/chat并且h..ps://my-url/another-page

我需要为主页添加相同的规则,应该是(我不确定/最后是否有):
h..ps://my-url

我应该在第一个条件中添加什么?就像是?

RewriteCond %{THE_REQUEST} (compile|chat|another-page|/) [NC]

标签: .htaccessmod-rewrite

解决方案


您可以只使用一个简单的表达式块(在 Apache 2.4 或更高版本中可用):

<If "%{REQUEST_URI} =~ m#^/(compile|chat|another-page)?$#">
    Header unset ETag
    Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
    Header set Pragma "no-cache"
    Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
</If>

推荐阅读