簡體   English   中英

301重定向到具有多站點/共享主機的非www ssl版本

[英]301 Redirect to non-www ssl Version with Multisite/Shared Hosting

我與Godaddy.com有一個共享的托管帳戶,用於托管五個不同的網站(site1.com,site2.com ... site5.com)。 我想將.htaccess文件放在/目錄中,該文件使所有五個不同的網站重定向到每個網站的非www和ssl版本。

現在,我的.htaccess文件中包含以下內容:

Options +FollowSymLinks -MultiViews
RewriteEngine On

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

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

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

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

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

站點的目錄結構已設置好,以便site1的index.html位於/public_html/index.html

其他四個站點的索引文件位於:/public_html/[site#]/index.html,其中四個站點用於[site#](site2 / site3 / site4 / site5 /)

當我在瀏覽器中鍵入網站2-4的URL的www版本時,服務器會自動重定向到https的https版本:

site#.com / other_sites / site#.com

我希望每個站點都重定向到ssl,即使訪問者未輸入站點的www版本。 我知道我需要額外的RewriteCond和RewriteRule,但是不知道要使用什么代碼。

我只是在學習RegEx和服務器配置,因此任何幫助將不勝感激。

您可以使用:

Options +FollowSymLinks -MultiViews
RewriteEngine On

RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [NE,L,R=301]
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]

暫無
暫無

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

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