【发布时间】:2017-06-17 21:47:46
【问题描述】:
我必须将我的域从 http 重定向到 https。在我的 htaccess 中我已经有了。
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
这个 sn-p 将所有不带“www”的内容重定向到“www”。
当我把它改成
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
结果是:
http://www.example.com/folder/page.php
becomes
Location => https://www.example.com/folder/page.php
很好!
https://example.com/folder/page.php
becomes
https://www.example.com/folder/page.php
很好!
但是:
http://example.com/folder/page.php
becomes
Location => https://example.com/folder/page.php
但必须是
Location => https://www.example.com/folder/page.php
如何解决这个问题?
我知道所有这些重定向:
RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
但我只需要一个重定向而不是两个 301。
【问题讨论】:
标签: .htaccess redirect https http-status-code-301