Using regular expressions with ‘not’ in .htaccess redirect

I’m having difficulty with a regular expression that starts with a ‘not’ in an .htaccess redirect.

I have a WordPress multisite (subdomain install) with a wildcard SSL certificate called Some blogs run on a subdomain. Others have their own domain name.

I want to redirect all URLs to https and all other URLs to http.

My .htaccess contains:

#Redirect * domains to https
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(.*.)?
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#Redirect non webhive domains to http
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^(.*.)?
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

The first block appears to work correctly, directing domains to https. The second block doesn’t.

Thanking you in advance!

Read more here: Using regular expressions with ‘not’ in .htaccess redirect

Leave a Reply

Your email address will not be published. Required fields are marked *