【问题标题】:Add www to urls having HTTPS将 www 添加到具有 HTTPS 的 url
【发布时间】:2013-11-26 16:10:18
【问题描述】:

我需要将 www 添加到所有开头没有 www 的 url(站点是在 drupal 中构建的)。我使用 htaccess 文件中的以下代码对 http 请求做了同样的事情。

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

现在我想为具有 https 的网址添加相同的内容,例如我需要将 https://example.com 重定向到 https://www.example.com

我尝试了几种方法都没有成功。请尽快帮助我。任何帮助将不胜感激。

【问题讨论】:

    标签: php apache .htaccess drupal drupal-7


    【解决方案1】:

    你可以用这个替换你的规则:

    RewriteCond %{HTTP_HOST} !^www\.
    RewriteCond %{HTTPS}s on(s)|
    RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
    

    【讨论】:

      【解决方案2】:

      将您的规则更改为:

      RewriteCond %{HTTP_HOST} !^www\. [NC]
      RewriteCond %{HTTPS}:s (on:(s)|off:s)
      RewriteRule ^ http%2://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
      

      【讨论】:

      • 嗨,乔恩,我已经尝试过您的代码,但它无法正常工作,并且出现 ssl 错误。我什至尝试过 anubhava 的建议(下一个),但那个也行不通。
      猜你喜欢
      • 1970-01-01
      • 2014-12-16
      • 2012-04-10
      • 2020-12-26
      • 2015-08-12
      • 1970-01-01
      • 2017-01-14
      • 2020-03-06
      • 1970-01-01
      相关资源
      最近更新 更多