[英].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.