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 webhive.com.au. Some blogs run on a webhive.com.au subdomain. Others have their own domain name.
I want to redirect all webhive.com.au URLs to https and all other URLs to http.
My .htaccess contains:
#Redirect *.webhive.com.au domains to https
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(.*.)?webhive.com.au
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#Redirect non webhive domains to http
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^(.*.)?webhive.com.au
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
The first block appears to work correctly, directing webhive.com.au domains to https. The second block doesn’t.
Thanking you in advance!
Read more here: Using regular expressions with ‘not’ in .htaccess redirect