可用的301重定向規(guī)則,
不帶www的域名重定向到帶www
不是https的域名重定向到https
ErrorDocument 404 /404.html
ErrorDocument 403 /403.html
RewriteEngine On
# ensure www.
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# ensure https
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
上邊那個是強制跳轉(zhuǎn)所有的子域名
需要指定域名才跳轉(zhuǎn)使用以下代碼:
# ensure www.
RewriteCond %{HTTP_HOST} ^jeawin.com [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# ensure https
RewriteCond %{HTTP_HOST} ^miniball.cn [NC]
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]