简体   繁体   中英

Redirecting to https with wildcard urls (htaccess)

I have the following problem. I have a site where some pages must be redirected to the https-secured equivalent of the link.

I tried several things but in the end it seems that the server ends up in a loop redirecting :(

Now I redirect every page to the https page but that is not what I want to.

This is the code I use right now:

RewriteCond %{http_host} ^www.domain.nl
RewriteCond %{SERVER_PORT}  !^443$
RewriteRule ^(.*)$ https://www.domain.nl/$1 [L,R=301]

I would like to have al urls starting with bo- have https.

examples:

http://www.domain.nl/bo-users -> redirects to https://www.domain.nl/bo-users
http://www.domain.nl/bo-groups -> redirects to https://www.domain.nl/bo-groups

but

http://www.domain.nl/about-us -> stays at http://www.domain.nl/about-us

It is clear to me I need some wildcards in the rewrite condition for all urls startin with bo-. We are using apache on the server. Hope someone can send me in the right direction.

Thanks,

Frank


Update after the tips from Anubhava.

I current;y have this htaccess but I can't get it working (even when clearing the cache in my browser)

Options +FollowSymlinks
RewriteEngine On
RewriteBase /


RewriteCond %{HTTP_HOST} ^www.domain\.nl$ [NC]
RewriteCond %{HTTPS} on
RewriteRule !^bo- http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NC,NE]

RewriteCond %{HTTP_HOST} ^www.domain\.nl$ [NC]
RewriteCond %{HTTPS} off
RewriteRule ^bo- https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NC,NE]


#rewrites een url to www. 
RewriteCond %{HTTP_HOST}  ^[a-z0-9-]+\.[a-z]{2,6}$ [NC]
RewriteRule ^(.*)$        http://www.%{HTTP_HOST}/$0 [L,R=301]


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php/$1 [L]

Hope for some extra help! Thanks, Frank

I just opened another call. The initial answer worked fine!

Use this rule:

# force HTTPS for bo- URIs
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.nl$ [NC]
RewriteCond %{HTTPS} off
RewriteRule ^bo- https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NC,NE]

# force HTTP for non bo- URIs
RewriteCond %{HTTP_HOST} ^www.domain\.nl$ [NC]
RewriteCond %{HTTPS} on
RewriteRule !^bo- http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NC,NE]

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