我刚刚重建并启动了一个网站(我们称之为example.com),并将旧网站分配了一个legacy.example.com子网。我需要允许人们在旧网站上访问他们的订单历史记录,但我不希望他们浏览产品并允许访问旧网站上的购物车和结帐。所以我需要重定向除登录/注销页面,帐户页面和收据页面之外的所有内容:
Login page = page.php?pg=extranet&mode=login
Logout page = page.php?pg=extranet&mode=logout
Account page = page.php?pg=extranet
Order listing page = page.php?pg=extranet&mode=orderstatus
Receipt page = receipt.asp
在一天中的大部分时间里,我一直在搞乱这个问题,并且已经在互联网上回来了,并且无法找到条件的“和”和“或”的神奇组合。它甚至可能还是需要将其分解为多个条件/规则集?我该怎么做?
RewriteCond %{REQUEST_URI} !^/receipt.asp [OR,NC]
RewriteCond %{REQUEST_URI} !^/page.asp [NC]
RewriteCond %{QUERY_STRING} !^pg=extranet [OR,NC]
RewriteCond %{QUERY_STRING} !^pg=extranet&mode=login [OR,NC]
RewriteCond %{QUERY_STRING} !^pg=extranet&mode=logout [OR,NC]
RewriteCond %{QUERY_STRING} !^pg=extranet&mode=orderstatus [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
答案 0 :(得分:2)
以其他方式进行,即如果输入URL在跳过重写时与上述任何条件匹配。
RewriteEngine On
# if login/logout/orderstatus don't do anything
RewriteCond %{QUERY_STRING} ^pg=extranet(&mode=(login|logout|orderstatus))?$ [NC]
RewriteRule ^page\.php$ - [L]
# if receipt page don't do anything
RewriteRule ^receipt\.php$ - [L,NC]
# otherwise redirect to new site
RewriteRule ^ http://www.example.com%{REQUEST_URI} [R=301,L,NE]