简体   繁体   English

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

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

I just rebuilt and launched a site (we'll call it example.com) and assigned a subdomain of legacy.example.com to the old site. 我刚刚重建并启动了一个网站(我们将其称为example.com),并为旧网站分配了legacy.example.com的子域。 I need to allow people to access their order history on the old site but I don't want them to be browsing the products and allowing access to the cart and checkout on the old site. 我需要允许人们在旧站点上访问他们的订单历史记录,但我不希望他们浏览产品并允许在旧站点上访问购物车和结帐。 So I need to redirect everything except the login/logout pages, the account page, and the receipt page: 因此,我需要重定向除登录/注销页面,帐户页面和收据页面以外的所有内容:

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

I've been messing with this for the better part of a day and have been all over the internet and back and can't find the magic combination of "and" and "or" for the condition. 在一天的大部分时间里,我一直在搞砸这个问题,并且遍及整个互联网,无法找到这种情况的“ and”和“ or”的神奇组合。 Is it even possible or do I need to break it into multiple Condition/Rule sets? 甚至有可能还是我需要将其分为多个条件/规则集? How would I do that? 我该怎么做?

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]

Do it other way round ie if input URL matched any of the above conditions when skip rewrites. 以其他方式进行操作,即,当跳过重写时,如果输入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