简体   繁体   中英

.htaccess rewrite to https

So I want to do the following:

  1. if the user tries to go to an ypart of the site other than index.php, they get redirected to the https version.

  2. so if they try to go to example.com/index.php they do not get redirected to the https version

  3. but if they go to any part of the site other than index.php (like welcome.php) they get redirected to the https version.

here's how I did full site https redirection before (I'm not sure how to do full site redirection to https example on index.php)

RewriteBase /
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ https://www.handybook.com/$1 [L,R=301]

RewriteCond %{HTTP_HOST} !^www.example.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]


# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# otherwise forward it to index.php
RewriteRule . index.php

In order to have all pages except for index redirect to https, add the following to your .htaccess file:

RewriteCond %{HTTPS} !on
RewriteRule !^(index)\.php$ https://%{HTTP_HOST}%{REQUEST_URI}

You can add additional exceptions using the pipe character within the parenthesis, like so:

RewriteRule !^(index|about|contact)\.php$ https://%{HTTP_HOST}%{REQUEST_URI}

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