从规则中排除网址或模式

时间:2013-03-15 11:51:21

标签: apache .htaccess rewrite

我想从规则中排除某些网址,但由于我对apache有绝对的了解,所以我似乎无法确定条件。

RewriteEngine On
RewriteCond %{HTTP:X_FORWARDED_PROTO} https
#RewriteCond %{REQUEST_URI} !^/(account|checkout|login) 
RewriteCond %{REQUEST_URI} !/account/login.html
RewriteCond %{REQUEST_URI} !/index.php?main_page=password_forgotten
RewriteCond %{REQUEST_URI} !/account/
RewriteCond %{REQUEST_URI} !/account/edit.html
RewriteCond %{REQUEST_URI} !/account/address-book/
RewriteCond %{REQUEST_URI} !^/account/change-password.html
RewriteCond %{REQUEST_URI} !^/account/notifications/
RewriteCond %{REQUEST_URI} !^/index.php?main_page=checkout&fecaction=null
RewriteCond %{REQUEST_URI} !^/index.php?main_page=checkout_shipping_address
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]

我相信应该有办法排除包含/ account /或= checkout的所有网址,但我不知道如何。

还有人可以解释一下^,(。*),$是什么?我认为他们是运营商,但我似乎无法找到任何信息,现在没有时间学习apache。

1 个答案:

答案 0 :(得分:0)

所有这些奇怪的字符都是正则表达式的一部分。有关详细信息,请参阅此处mod_rewrite Introduction- Regular Expressions

您可以省略所有

RewriteCond %{REQUEST_URI} !/account/login.html
RewriteCond %{REQUEST_URI} !/account/edit.html
RewriteCond %{REQUEST_URI} !/account/address-book/
RewriteCond %{REQUEST_URI} !^/account/change-password.html
RewriteCond %{REQUEST_URI} !^/account/notifications/

因为

RewriteCond %{REQUEST_URI} !/account/

已经涵盖了所有这些。

=checkout的测试不同,因为它不是URL路径的一部分,而是查询字符串的一部分。排除每个请求,包括查询字符串中的=checkout

RewriteCond %{QUERY_STRING} !.=checkout