繁体   English   中英

仅将主页从http重定向到https的规则

[英]Redirect rule for only home page from http to 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/

这是不安全的。 阅读OWASP a9并设置HSTS标志,以使整个网站仅使用HTTPS。

HTTP是一个错误,如果您这样做是出于“性能”的考虑,那么您就是个傻瓜。 HTTPS的重量极轻。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM