测试文章
普通的方法,只能实现网站首页https,
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.cglw.com$ [NC]
RewriteRule ^(.*)$ https://www.cglw.com/$1 [L,R=301]
用以下代码,才可以实现整站http301跳转至https,
RewriteEngine On
RewriteBase /
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]
.htaccess 一段神奇的跳转代码
写在.htaccess中
一:http跳转https
RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{SERVER_NAME}/$1 [R=301,L]
二:不带www跳转到带www
RewriteCond %{http_host} ^ub07.com [NC]
RewriteRule ^(.*)$ http://www.ub07.com/$1 [L,R=301]
三:带www跳转到不带www
RewriteCond %{http_host} ^www.jipinji.cn [NC]
RewriteRule ^(.*)$ http://jipinji.cn/$1 [L,R=301]
#开启伪静态
RewriteEngine On
#http 301重定向到https, 并且不带www跳转到带www
RewriteCond %{HTTP_HOST} ^123.com [NC]
RewriteRule ^(.*)$ https://www.123.com/ https://www.123.com/$1 [L,R=301]
RewriteEngine on
RewriteBase /
RewriteCond %{SERVER_PORT} !^443 https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
重要提示:必须将代码放到.htaccess文件内容的最前面,以保证重定向优先权,如果与本身有的规则重复,只需写4、5行即可。
RewriteEngine On
RewriteBase /
RewriteCond %{SERVER_PORT} !^443 https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]