繁体   English   中英

通过htaccess将http://重定向到https://www.www

[英]http:// redirects to https://www.www with htaccess

我在根域中安装了CI。 SSL证书已安装且正常运行。 当我将http://重定向到https:// www时,它也重定向到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/$1 [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/$1 [L]
</IfModule>

我正在使用Centos VPS在apache上运行它。

非常感谢!

HTTP_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时,需要添加条件。 在此规范的解决方案中, 查看Canonical主机上的Apache文档questions / 4083221 / how-to-redirect-all-http-requests-to-https

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM