2011-06-10 148 views
2

我想重定向所有子域(我在apache的虛擬主機設置通配符子域)到HTTPS,如果使用HTTP,所有除了www.domain.comhtaccess的重定向所有子域到https除了WWW

任何非常感激的想法。

這是我到目前爲止有:

# Redirect subdomains to https 
#RewriteCond %{HTTPS} off 
#RewriteCond %{HTTP_HOST} ^(*)\. [NC] 
#RewriteCond %{HTTP_HOST} !^(www)\. [NC] 
#RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L] 

謝謝!

回答

5

在.htaccess文件試試這個代碼:

Options +FollowSymlinks -MultiViews 
RewriteEngine On 

RewriteCond %{SERVER_PORT} =80 
RewriteCond %{HTTP_HOST} !^www\. [NC] 
RewriteRule^https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 
+0

優秀的感謝! – 2011-06-13 09:36:05

2

這會幫助你:

RewriteCond %{HTTP_HOST} !^(www\.)localhost.com$ 
RewriteCond %{HTTP_HOST} ^(.*?)\.localhost.com$ 
RewriteCond %{HTTPS} !=on 
RewriteRule ^(.*?)$ https://%{HTTP_HOST} [nc] 

首先RewriteCond:如果網站不以www

RewriteCond啓動:得到任何的子域

RewriteCond:檢查HTTPS ISN」 t已經在請求的URL中

RewriteRule:重定向到https版本網站

相關問題