簡體   English   中英

如何使用 htaccess 將多個域重定向到除 1 個目錄之外的另一個域?

[英]How to redirect multiple domains to another domain except 1 directory using htaccess?

我正在嘗試將多個域重定向到一個域(工作正常),但我希望一個目錄不重定向或更改主域 url。

這是我的 .htaccess 代碼,它工作正常,直到這里

這個正在工作

<pre>
    RewriteCond %{HTTP_HOST}    ^http(s)?://(www.)?domain.com$  [OR]
    RewriteCond %{HTTP_HOST}    ^http(s)?://(www.)?domain.net$  [OR]
    RewriteCond %{HTTP_HOST}    ^http(s)?://(www.)?domain.org$  [OR]
    RewriteCond %{HTTP_HOST}    ^domain.info$ [OR]
    RewriteCond %{HTTP_HOST}    !^www.domain.info
    RewriteRule (.*)    http://www.domain.info/$1   [R=301,L]
</pre>

但是當我嘗試通過以下方式停止重定向一個特定目錄時

完整代碼

<pre>
    RewriteCond %{HTTP_HOST}    ^http(s)?://(www.)?domain.com$  [OR]
    RewriteCond %{HTTP_HOST}    ^http(s)?://(www.)?domain.net$  [OR]
    RewriteCond %{HTTP_HOST}    ^http(s)?://(www.)?domain.org$  [OR]
    RewriteCond %{HTTP_HOST}    ^domain.info$        [OR]
    RewriteCond %{HTTP_HOST}    !^www.domain.info   [OR]
    RewriteCond %{REQUEST_URI}  !^/no_redirect_dir/
    RewriteRule (.*)    http://www.domain.info/$1   [R=301,L]
</pre>

一切都停止工作:(出現錯誤,頁面未正確重定向。

導致錯誤的額外代碼

<pre>
    RewriteCond %{HTTP_HOST}    !^www.domain.info   [OR]
    RewriteCond %{REQUEST_URI}  !^/no_redirect_dir/
</pre>

任何幫助將不勝感激。

謝謝你!

像這樣寫你的 .htaccess:

RewriteCond %{HTTP_HOST} (www\.)?domain\.(org|net|com)$ [NC]
RewriteCond %{REQUEST_URI} !^/*no_redirect_dir/ [NC]
RewriteRule ^(.*)$ http://www.domain.info/$1 [R=301,L]

HTTP_HOST 變量只有域名,沒有 http/https 信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM