强制通过htaccess文件重定向到https

时间:2017-05-13 16:09:08

标签: .htaccess https url-redirection http-redirect

我想强制将对我网站的任何访问重定向到https 我的htaccess规则如下:

# rewrite address
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mytestsite\.eu$ [NC]
RewriteRule ^(.*)$ https://www.mytestsite.eu/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ https://www.mytestsite.eu/$1 [R=301,L]

#RewriteCond %{HTTP_HOST} ^(.+)\.mytestsite\.eu$   [NC] 
#RewriteCond %{HTTP_HOST} !^www\. 
#RewriteRule ^ https://www.mytestsite.eu/  [L,R] 

我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:1)

重写前三行:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]