【发布时间】:2014-11-12 00:05:10
【问题描述】:
目前,我的 htaccess 文件将我所有子域的非 https 请求重定向到 https...,除了 www 请求。 IE。 http://subdomain.example.com 被重定向到 https://subdomain.example.com(这是正确的),但 www.subdomain.example.com 被重定向到 https://www.subdomain.example.com(不正确)。这是我的 .htaccess 代码:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Trying to redirect to https
RewriteCond %{HTTPS} off
RewriteCond %{SERVER_PORT} !=443
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,NE,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
【问题讨论】:
-
阅读评论
# Trying to redirect to https下的三行如果HTTPS如果关闭并且我们不在端口443上提供服务,则重定向到主机(http://和.com之后的尾随/之间的所有内容) .您实际上是使用他们为主机放置的任何内容将所有内容重定向到 HTTPS。 -
没错,但这并不能回答我的问题。我将如何修改此代码以将 www 也重定向到 https?我是 htaccess 方面的初学者。
标签: php apache .htaccess mod-rewrite redirect