简体   繁体   中英

Redirect to https except one link

I use this code for redirect all link to https and www

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

RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

But i want one link not redirect to https

Example :

http://myname.com --> https://www.myname.com
http://myname.com/file.php -- > https://www.myanem.com/file.php
http://myname.com/except.php -- > http://www.myanem.com/except.php

In top example , i want except.php not redirect to https

This should do:

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/except\.php$
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} ^/except\.php$
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ %{REQUEST_SCHEME}://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

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