【问题标题】:htaccess force www to non-www with consideration of http or httpshtaccess 在考虑 http 或 https 的情况下将 www 强制为非 www
【发布时间】:2013-07-24 16:27:06
【问题描述】:

我真的被困在转换这个漂亮的 htaccess 脚本(规则)上帮我?

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

谢谢你,我真的被那些 htaccess 符号困住了!

【问题讨论】:

标签: .htaccess redirect


【解决方案1】:

为了使www to non-www 上面的代码不起作用,因为变量捕获在 RewriteCond 中的工作方式。您需要将它们分解为 2 条规则,如下所示:

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

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

【讨论】:

    猜你喜欢
    • 2014-12-16
    • 2011-06-17
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-04
    • 2013-04-22
    • 1970-01-01
    相关资源
    最近更新 更多