1

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]
1
  • Please note that query string variables can appear in any order, so people can still access the page if they go to page.php?mode=login&pg=extranet etc.
    – Sumurai8
    Nov 10, 2013 at 14:27

1 Answer 1

2

Do it other way round i.e. 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]
3
  • 1
    +1, yes very good simplification as always done by @anubhava.
    – jacouh
    Nov 10, 2013 at 14:41
  • That works! Thank you! And now I've noticed it also excludes my css and js files that are needed for page display. Oops! How do I exclude them from being redirected also? The files are in the /css and /js directories. Nov 10, 2013 at 14:43
  • @jacouh: Thanks so much. Michelle: You can modify 2nd rule as: RewriteRule ^receipt\.php|css/|js/ - [L,NC] to skip css, js files
    – anubhava
    Nov 10, 2013 at 14:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.