简体   繁体   中英

.htaccess - redirect http to https exclude specific url

How to redirect http to https exclude specific url?

http://www.example.com/* => https://www.example.com/*
http://www.example.com/nonssl/* => http://www.example.com/nonssl/*

So I make .htaccess file following this:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/nonssl/
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

But when I go to http://www.example.com/nonssl/testfunc , it goes to https://www.example.com/index.php/nonssl/testfunc .

Thanks in advance.

For this problem, I didn't find the correct way, just describe all services to redirect from http to https.

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^/$ [OR]
RewriteCond %{REQUEST_URI} ^/test [OR]
RewriteCond %{REQUEST_URI} ^/test1 [OR]
RewriteCond %{REQUEST_URI} ^/test2
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|css|fonts|js|robots\.txt)
RewriteRule ^(.*)$ index.php?/$1 [L]

I know it just not recommended way. If who can fix this problem just connect me. Thanks.

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