http:// 使用 htaccess 重定向到 https://www.www

http:// redirects to https://www.www with htaccess

我在我的根域中安装了 CI。 SSL 证书已安装并正常工作。当我将 http:// 重定向到 https://www it redirects to https://www.www(一个额外的 www)时,正如用户所报告的那样,在某些计算机和某些浏览器上也是如此。但是,当我从重定向中删除 'www' 时,一切都很好。好像 www 正在循环。到目前为止,我已经挖掘了我的代码数百次,并没有看到从代码重定向的迹象(我的意思是添加额外的 www)。我正在用 htaceess 做这件事。任何帮助将不胜感激。这是我的 htaccess:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

#Force SSL
RewriteCond %{HTTPS} !on
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [R,L]

#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/ [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/ [L]
</IfModule>

我 运行 在 Apache 上使用 Centos VPS。

非常感谢!

HTTP_HOST 是请求的 "target host" 部分,例如:www.mydomain.com.
REQUEST_URI一般是为了访问某个页面而给出的路径;例如,“/folder/index.html”。

在您的 RewriteRule 中,您说将 'www.' 放在请求的域名前面。
当有人要求 http://www.yourdomain.com.
时,您不希望这样 没有 www。在您的 RewriteRule 中,请求 http://yourdomain.com 的人被重定向到 https://yourdomain.com

当你想重定向到 https 和 www 时,你需要添加条件。查看此解决方案的 Apache docs on Canonical host and on :

RewriteCond %{HTTPS} !=on [OR]  
RewriteCond %{HTTPS_HOST} !^www.yourdomain.com$ [NC]  
RewriteRule ^(.*)$ https://www.yourdomain.com/ [L,R=301]