繁体   English   中英

.htaccess-重定向除一页和另一页(取决于其查询字符串)以外的所有页面

[英].htaccess - redirect all pages except for 1 page and another page depending on it's querystring

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

在一天的大部分时间里,我一直在搞砸这个问题,并且遍及整个互联网,无法找到这种情况的“ and”和“ or”的神奇组合。 甚至有可能还是我需要将其分为多个条件/规则集? 我该怎么做?

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]

以其他方式进行操作,即,当跳过重写时,如果输入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]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM