htaccess 301重定向规则

可用的301重定向规则,
不带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]

上边那个是强制跳转所有的子域名

需要指定域名才跳转使用以下代码:

# ensure www.
RewriteCond %{HTTP_HOST} ^jeawin.com [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# ensure https
RewriteCond %{HTTP_HOST} ^www.jeawin.com [NC]
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]


昵称*:
邮箱地址*:
评分*:
内容*: