.htaccess实现全站http301重定向到https(ssl)
问题描述:
.htaccess怎么实现全站http301重定向到https(ssl),包括内页url?
问题解决方法:
其实实现http全站301到https用到的核心代码如下:
RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]
后来按照这个把.htaccess设置的代码如下:
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>
然后发现我网站内页的url全部到了https://www.b1y.cn/index.php,说明这样设置行不通。发现不能单独的复制,后来把规则修改了下,如下:
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301] RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] RewriteCond %{HTTP_HOST} ^b1y.cn$ RewriteRule ^(.*)$ http://www.b1y.cn/$1 [R=301,L] </IfModule>
这样修改后,然后去测试发现,已经实现了全站http到https(ssl),最后成功的代码,大家可以参考下。
要自己调试适合自己的
文章不错支持一下吧
不错,支持一下!
比别人多一点执着,你就会创造奇迹 www.aaa137.com
在昵称里可以留网址 评论里 尽量不要出现网址了!
RewriteRule ^(.*)$ http://www.b1y.cn/$1
不是https ?
上面301了 这个是301 www和不带www的