簡體   English   中英

Htaccess多域,但重定向一個域(除特定路徑外)

[英]Htaccess Multi domain, but redirect one domain except a specific path

我有一個配置為htaccess的多域,這意味着取決於輸入的域名,顯示的相關內容並將其重定向到任何域的https版本

我在.htacess中嘗試過的內容的一小段

RewriteEngine on
RewriteCond %{HTTP_HOST} ^arabme.com$ [NC]
RewriteRule ^(.*)$ https://www.arabme.com$1 [R=301,L]

RewriteEngine on
RewriteCond %{HTTP_HOST} ^chiname.com$ [NC]
RewriteCond %{REQUEST_URI} !^/(landing|marketing)
RewriteRule ^(.*)$ https://www.greatwall.com$1 [R=301,L]

但是在chiname.com我想將所有重定向到http://www.greatwall.com (兩個文件夾除外)。 /landing/marketing

因此,每當用戶輸入chiname.com/landing/*.phpchiname.com/marketing/*.php ,都需要顯示而不重定向到https://www.greatwall.com以及有關chiname.com所有其他路徑需要重定向到https://www.greatwall.com

當我從chiname.com訪問任何/landing/marketing文件夾時,無論我是否使用rewriteCond,以上內容都將始終重定向至https://www.greatwall.com/

注意:我沒有服務器級別的特權,所以我無權訪問VirtualHost .conf文件。

可以說,最好在主httpd-vhosts.conf文件的<VirtualHost>指令中執行此操作-但這不是一個選擇:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^arabme.com$ [NC]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.arabme.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^chiname.com$ [NC]
RewriteCond %{REQUEST_URI} !^/(landing|marketing)
RewriteRule ^(.*)$ https://www.greatwall.com/$1 [R=301,L]

假設您的.htaccess文件位於文檔根目錄下,那么您會遇到一些錯誤:

1:您無需在以下位置重復RewriteEngine On

2:你會錯過了/在后greatwall.com RewriteRule ,這意味着重定向會去//www.greatwall.comwhatever:HTTPS ,而不是https://www.greatwall.com/whatever


我在htaccess.madewithlove.be上對此進行了測試,因此它應該可以工作。

暫無
暫無

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

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