[英]htaccess redirects with subdomains and https
我正在使用托管兩個域(都使用SSL)的HostGator帳戶。 我在這兩個不使用SSL的站點上都設置了子域。 我已經設置了重定向,以便http可以重定向到https,但是在使用子域時遇到了問題。
這是我需要做的:
http : //site1.com- > https://site1.com
http://www.site1.com- > https://site1.com
dev.site1.com->沒有重定向
http : //site2.com- > https://site2.com
http://www.site2.com- > https://site2.com
dev.site2.com->沒有重定向
現在發生的是,當我轉到dev.site2.com時(無論是否放入https),我看到的是https://site1.com ,盡管它似乎沒有被重定向,因為地址欄仍然顯示dev.site2.com
這是我在htaccess中擁有的東西:
RewriteEngine On
RewriteBase /~hostgatorusername/
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteCond %{HTTP_HOST} !=dev.*
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /~hostgatorusername/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /~hostgatorusername/index.php [L]
</IfModule>
# END WordPress
我仍在嘗試完全掌握htaccess,因此,如果有人可以幫助我了解我在做什么錯,我很樂意。 謝謝!
更新:我還需要https://www.site1.com重定向到https://site1.com和https://www.site2.com重定向到https://site2.com
試試這個代碼:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /~hostgatorusername/
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^dev\. [NC]
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule .* https://%1%{REQUEST_URI} [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /~hostgatorusername/index.php [L]
</IfModule>
# END WordPress
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.