简体   繁体   中英

.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. 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. 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.

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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