Home .htaccess; redirect all https:// to http:// expect of two domains
Reply: 2

.htaccess; redirect all https:// to http:// expect of two domains

David
1#
David Published in 2017-11-14 08:06:41Z

I have this code to redirect all https:// to http://:

RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

But how can I exclude two domains www.example.com and www.test.com from this rule?

anubhava
2#
anubhava Reply to 2017-11-14 08:49:15Z

You can use a negative RewriteCond:

RewriteEngine On

RewriteCond %{HTTP_HOST} !^(?:www\.)?(?:test|example)\.com$ [NC]
RewriteCond %{HTTPS} on
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

Make sure to clear your browser cache before testing this change.

Lag
3#
Lag Reply to 2017-11-14 08:49:49Z

You need to include two Rewrite Conditions:

RewriteCond %{HTTP_HOST} !^www\.example\.com%{REQUEST_URI} [NC,OR]
RewriteCond %{HTTP_HOST} !^www\.test\.com%{REQUEST_URI} [NC]

This will excluded both of those domains as well as any directories within the domain and keep them as HTTPs. So your code should now look like:

RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\.example\.com%{REQUEST_URI} [NC,OR]
RewriteCond %{HTTP_HOST} !^www\.test\.com%{REQUEST_URI} [NC]
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Make sure you clear your cache before testing this.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.303505 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO