【问题标题】:301 Redirect HTTP to HTTPS - non-www to www301 将 HTTP 重定向到 HTTPS - 非 www 到 www
【发布时间】:2018-10-19 12:42:33
【问题描述】:

我正在寻找完美的 301 重定向 HTTP 到 HTTPS - 非 www 到 www。但我找不到可行的解决方案。

这就是我想做的事

http://domain.tld/ → https://www.domain.tld/
http://www.domain.tld/ → https://www.domain.tld/
https://domain.tld/ → https://www.domain.tld/

在这篇文章中:Best Practice: 301 Redirect HTTP to HTTPS (Standard Domain)

结论是:

    RewriteEngine On 
    RewriteCond %{HTTPS} off [OR]
    RewriteCond %{HTTP_HOST} ^www\. [NC] 
    RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,L,NE] 

但这是用于 www。到非www。

请帮忙。

谢谢,

【问题讨论】:

    标签: .htaccess url url-redirection http-redirect


    【解决方案1】:

    不确定您是否需要多个域或仅一个域,但这里有一个支持多个域的示例。由于您希望在所有域上都使用 www 和 https,因此我只是对其进行了硬编码。如果 url 中有子域,这应该也跳过重写。您可能需要对其进行调整以支持带点的 TLD(即 .co.uk、.co.au 等)。

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
    RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [L,R=301]
    

    【讨论】:

      猜你喜欢
      • 2019-08-12
      • 2017-05-03
      • 2019-02-04
      • 1970-01-01
      • 2018-09-26
      • 1970-01-01
      • 2017-11-24
      • 2017-03-24
      • 1970-01-01
      相关资源
      最近更新 更多