【发布时间】:2018-09-11 18:48:38
【问题描述】:
很长一段时间以来,我们的网站都在前面没有 www 的情况下运行,但最近我们不得不做出改变。
我们最近从 domainhere.com 更改为 www.domainhere.com。我们已经有一个从 http 到 https 的重定向,但需要将重定向从 https://domainhere.com 更改为 https://www.domainhere.com。
我们使用了这个代码。我们如何让它仍然重定向到 HTTPS 但前面有 www?
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.skarpeknive.dk/$1 [R,L]
我们在 Stackoverflow 上找到了这个,但它似乎不起作用。然后是 domainhere.com 上的站点错误
#First rewrite any request to the wrong domain to use the correct one (here www.)
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#Now, rewrite to HTTPS:
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
【问题讨论】:
-
您的规则看起来应该有效。在测试规则之前您是否清除了浏览器缓存?
-
你好。我做到了。我会说它也应该工作。也许我的电脑需要一段时间来调整。你能测试一下吗?该网站是 skarpeknive.dk
标签: .htaccess redirect mod-rewrite https url-redirection