[英]How to redirect all pages in the subdomain except a few?
我正在一個子域上,在該子域中,我需要將除少數頁面之外的所有頁面重定向到主域。
例如, http://subdomain.domain.com/contact-us
和http://subdomain.domain.com/thank-you
頁面不應重定向。 所有其他頁面都應重定向到http://www.domain.com
。
主域托管在其他位置,子域指向我可以訪問的服務器。 在子域的.htaccess中,我可以有這樣的內容:RewriteEngine On RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.domain\.com
RewriteRule ^(.*)/?!(contact-us|thank-you)$ http://www.domain.com/$1 [R=301,L]
您接近:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.domain\.com
RewriteRule ^(?!(?:contact-us|thank-you))(.*)/?$ http://www.domain.com/$1 [R=301,L,NE]
否定的超前(?!(?:contact-us|thank-you))
確保后續操作既不是contact-us
也不是thank-you
。
參考
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.