【问题标题】:www doesn't redirect to non www with https onwww 不会重定向到带有 https 的非 www
【发布时间】:2021-02-08 17:15:34
【问题描述】:

我的问题是当我在浏览器中输入example.comwww.example.com 时,它会重定向到https://example.com,但是当我输入https://www.example.com 时,它不会重定向到https://example.com

我想要 URL http 或 https 和 www 或非 www,它总是指向 https://example.com

我已经使用下面的 url 重写 htaccess 文件。

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]

提前致谢。

【问题讨论】:

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


【解决方案1】:

对于您显示的示例,您能否尝试以下操作。请确保在测试 URL 之前清除浏览器缓存。

还要确保这应该是 .htaccess 文件中的 TOP MOST 规则。

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

这应该将 url 重定向到没有 www 的 https,无论 url 有 http 还是 https 或 url 有 www 或没有 www。

【讨论】:

    猜你喜欢
    • 2015-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-09
    • 2016-04-27
    • 1970-01-01
    • 2018-04-22
    相关资源
    最近更新 更多