【发布时间】:2014-02-24 20:04:04
【问题描述】:
这是一个几乎相同问题htaccess for redirecting non-www to www while preserving http & https的链接
相反的情况如何写 - 我想在保留 http 或 https 的同时将 www 重定向到非 www,无论链接最初可能是什么
【问题讨论】:
这是一个几乎相同问题htaccess for redirecting non-www to www while preserving http & https的链接
相反的情况如何写 - 我想在保留 http 或 https 的同时将 www 重定向到非 www,无论链接最初可能是什么
【问题讨论】:
你可以有这两条规则:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\.(.+)$
RewriteRule ^ http://%1%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.(.+)$
RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301]
【讨论】:
经过一些试验和错误,这是有效的:
# Make all http use https and force non-www
<IfModule mod_rewrite.c>
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule ^(.*)$ https://mysite.ca%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>
抱歉没有早点回来发帖,我正在学习...
【讨论】: