【问题标题】:Want to redirect my site from www to non.www https想将我的网站从 www 重定向到 non.www https
【发布时间】:2020-12-31 06:47:49
【问题描述】:

我想将我的网站从带有 www 的 HTTP 重定向到 HTTPS 非 www 我使用了以下代码,但它不起作用。

RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]

RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]

【问题讨论】:

  • 您只需要在第二个条件中添加OR 即可使其成为RewriteCond %{HTTP_HOST} ^www\. [NC,OR]

标签: apache .htaccess redirect mod-rewrite url-rewriting


【解决方案1】:

您在修改规则后走在正确的道路上可能会对您有所帮助。请确保在测试 URL 之前清除浏览器缓存。

这些规则将从 www 或没有 www 重定向到 https。

RewriteEngine ON
RewriteCond https !on
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.*)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,NE,L]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-07
    • 2019-10-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多