【问题标题】:Redirection from http to https is not working从 http 到 https 的重定向不起作用
【发布时间】:2018-05-02 17:54:41
【问题描述】:
重写引擎开启
重写条件 %{SERVER_PORT} !443
RewriteRule ^(/(.*))?$ https://%{HTTP_HOST}/$1 [R=301,L]
这是我在 .htaccess 文件中使用的命令,当我键入 arion-software.co.uk 时,它没有正确重定向。
有什么想法吗?
【问题讨论】:
标签:
apache
.htaccess
redirect
mod-rewrite
https
【解决方案1】:
好了,http 到 https 重写:
## Redirecting HTTP to HTTPS
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
【解决方案2】:
这应该可以,它对我有用。
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]
这就是我的来源:redirect http to https
编辑:该链接为您的域提供了带有或不带有“www”的示例。子域。
【解决方案3】:
RewriteEngine On
RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don't put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
# [NC] is a case-insensitive match
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]