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

问题描述 投票:0回答:1

我想强制将对我网站的任何访问重定向到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] 

我该怎么做到这一点?

.htaccess https url-redirection http-redirect
1个回答
1
投票

像这样重写前三行:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]
© www.soinside.com 2019 - 2024. All rights reserved.