Thursday, 19 September 2013

301 redirect for entire site except for subdomains

301 redirect for entire site except for subdomains

I have setup a sitewide 301 redirect in my .htaccess as follows
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^.* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
But I wanted to exclude subdomains (support, blog) from being included in
this redirect. So I add the following RewriteConditions
RewriteEngine On
RewriteCond %{HTTP_HOST} !=support.example.com
RewriteCond %{HTTP_HOST} !=blog.example.com
RewriteCond %{HTTPS} !=on
RewriteRule ^.* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
This works totally fine. However I wonder if there is a better way to
specify the exclusion for all subdomains (not WWW) in just 1 RewriteCond
statement (instead of a separate RewriteCond for each subdomain)
I have a few more subdomains and plan to add some more. Would appreciate
the help.

No comments:

Post a Comment