重定向规则到https
问题描述:
我们能否HTTPS仅供主页即对于重定向规则到https
example.com 或http://example.com或 www.example.com 或http://www.example.com
剩下的所有页面应该以http开头。
我已经试过这样的,但它没有工作
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} "^/$"
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} ^(.*)$
RewriteRule ^(.*) http://%{HTTP_HOST}%{REQUEST_URI}
答
没有真正测试,但应该做的魔术
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^/?$ https://%{HTTP_HOST}/ [R,L]
RewriteCond %{SERVER_PORT} ^443$
RewriteRule !^/?$ http://%{HTTP_HOST}%{REQUEST_URI} [R,L]
答
您还可以在根级别重定向这样的的.htaccess :
DirectoryIndex index.html
Redirect 301 /index.html https://www.website.com/