【问题标题】:.htcaccess redirect no www to www with SSL.htaccess 使用 SSL 将非 www 重定向到 www
【发布时间】: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


【解决方案1】:

可能是代理问题,试试这个:

RewriteCond %{HTTP:X-Forwarded-Proto} !https [OR]
RewriteCond %{HTTP_HOST} !^www\. [OR]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

注意:清除浏览器缓存然后测试

【讨论】:

  • 没有任何改变。如果您打开 skarpeknive.dk,它会将您发送到 www 吗?即使我清除了它也一定只是我的缓存窃听。
猜你喜欢
  • 1970-01-01
  • 2010-12-01
  • 2014-11-24
  • 1970-01-01
  • 2012-10-19
  • 1970-01-01
  • 2012-11-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多