2015-09-07 108 views
0

我想要一個將所有內容重定向到https://和www的重寫規則。htaccess - 重寫規則SSL重定向到https:// www

例如https://lalna.com應該去https://www.lalna.com

這是我有:

RewriteEngine On 
RewriteCond %{SERVER_PORT} !=443 
RewriteCond %{HTTP_HOST} ^(www\.)?DOMAIN\.com$ [NC] 
RewriteRule ^(.*)$ "https\:\/\/www\.DOMAIN\.com\/$1" [R=301,L] 
+0

我跟着網站,所以我只是用它。但它爲我的網站工作https://wiki.apache.org/httpd/RewriteHTTPToHTTPS –

回答

0

我找到了解決辦法。

RewriteCond %{HTTPS} off 
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
RewriteCond %{HTTP_HOST} !^www\. 
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
0
RewriteEngine On 
# This will enable the Rewrite capabilities 

RewriteCond %{HTTPS} !=on 
# This checks to make sure the connection is not already HTTPS 

RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L] 
# This rule will redirect users from their original location, to the same location but using HTTPS. 
# i.e. http://www.example.com/foo/ to https://www.example.com/foo/ 
# The leading slash is made optional so that this will work either in httpd.conf 
# or .htaccess context 

我通過它去了,它爲我工作。這裏就是我從https://wiki.apache.org/httpd/RewriteHTTPToHTTPS有我

+0

這與我目前的工作相同。我希望https://lalna.com使用「www」轉到https://www.lalna.com。 – Will

0

嘗試:

RewriteEngine On 
RewriteCond %{HTTPS} on 
RewriteCond %{HTTP_HOST} ^DOMAIN\.com$ [NC] 
RewriteRule ^(.*)$ https://www.DOMAIN.com/$1 [NC,R,L] 

這將重定向SSL非www(https://domain.com)至(https://www.domain.com

如果你想重定向非SSL和非www (http://domain.com)至(https://www.domain.com),然後嘗試:

RewriteEngine On 
RewriteCond %{HTTPS} off 
RewriteCond %{HTTP_HOST} ^DOMAIN\.com$ [NC] 
RewriteRule ^(.*)$ https://www.DOMAIN.com/$1 [NC,R,L] 
+0

對不起,沒有工作。我已將域名更改爲我的域名,並且與我的域名一樣。 – Will

+0

清除瀏覽器的緩存並再試一次。 – starkeen

+0

我剛剛訪問過您的網站,其工作正常。 – starkeen