简体   繁体   中英

Redirect rule for only home page from http to https

Can we make https for only home page ie, for

example.com or http://example.com or www.example.com or http://www.example.com

remaining all pages should start with http.

I have tried like this but it isn't worked

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} "^/$"
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} ^(.*)$
RewriteRule ^(.*) http://%{HTTP_HOST}%{REQUEST_URI}

Not really tested but should do the magic

RewriteEngine On

RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^/?$ https://%{HTTP_HOST}/ [R,L]

RewriteCond %{SERVER_PORT} ^443$
RewriteRule !^/?$ http://%{HTTP_HOST}%{REQUEST_URI} [R,L]

You can also redirect like this in a .htaccess at root level:

DirectoryIndex index.html
Redirect 301 /index.html https://www.website.com/

This is not secure. Read OWASP a9 and set the HSTS flag to make your entire website HTTPS only.

HTTP is a mistake and if you are doing this for "performance" you are a fool. HTTPS is extremely light weight.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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