1

我刚刚重建并启动了一个站点(我们将其称为 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]
4

1 回答 1

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]
于 2013-11-10T14:23:48.553 回答