将站点重定向到https后,站点IP重定向不起作用

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

我正在使用.htaccess将我网站上的所有内容重定向到https。例如,http://example.se重定向到https://www.example.se。一切似乎都有效,除了网站ip 111.111.111.111现在重定向到https://www.111.111.111.111而不是网站https://www.example.se

这是我的.htaccess代码

RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [L,NE,R=301]
Options -Indexes
.htaccess redirect ip
1个回答
0
投票

尝试:

RewriteEngine On

# redirect http to https
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.example.se/$1 [L,NE,R=301]

# redirect non-www to www
RewriteCond %{HTTP_HOST} !^www.example.se [NC]
RewriteRule ^(.*)$ https://www.example.se/$1 [L,NE,R=301]
© www.soinside.com 2019 - 2024. All rights reserved.