Force WWW and ignore subdomain

Posted about 9 months ago

Following on from the post where I explain how to force WWW, I’ve found with development domains (dev.domain.com) the htaccess is breaking the site, in the interest of keeping staging and production like for like I’ve added the following lines to my htaccess.

RewriteCond %{HTTP_HOST} !^dev\.domain\.com$ [NC]

So my Htaccess looks like the following, I have my conditions and then the rule.


RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} !^dev\.domain\.com$ [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]