多个RewriteCond用于多个RewriteRules

时间:2011-05-30 00:03:26

标签: .htaccess mod-rewrite

我正在使用这些重写规则,只有在没有“用户”cookie时才会生效。

RewriteCond %{HTTP_COOKIE} (user)
RewriteRule (.*)? - [S=5] # Skip the below 5 lines if the above test passes
RewriteRule ^$ app/webroot/cache_static_html/cache_static_popular_results_1.html [L]
RewriteRule ^popular/page:2$ app/webroot/cache_static_html/cache_static_popular_results_2.html [L]
RewriteRule ^popular/page:3$ app/webroot/cache_static_html/cache_static_popular_results_3.html [L]
RewriteRule ^popular/page:4$ app/webroot/cache_static_html/cache_static_popular_results_4.html [L]
RewriteRule ^popular/page:5$ app/webroot/cache_static_html/cache_static_popular_results_5.html [L]

现在,我如何添加另一个不能有查询字符串值的条件?如果有“用户”cookie或查询字符串,则应跳过这5条规则。

1 个答案:

答案 0 :(得分:2)

RewriteCond %{HTTP_COOKIE} (user) [OR]
RewriteCond %{QUERY_STRING} ^user=(.*) #assuming ?user=xyz
RewriteRule (.*)? - [S=5] # Skip the below 5 lines if the above test passes
RewriteRule ^$ app/webroot/cache_static_html/cache_static_popular_results_1.html [L]
RewriteRule ^popular/page:2$ app/webroot/cache_static_html/cache_static_popular_results_2.html [L]
RewriteRule ^popular/page:3$ app/webroot/cache_static_html/cache_static_popular_results_3.html [L]
RewriteRule ^popular/page:4$ app/webroot/cache_static_html/cache_static_popular_results_4.html [L]
RewriteRule ^popular/page:5$ app/webroot/cache_static_html/cache_static_popular_results_5.html [L]