Hi there,
I want to use a rewrite rule to ensure that 'www' is always in a live site's URL. I'd normally use the following:
RewriteEngine On
# Add www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
However, this particular website has a live URL (http://www.mywebsite.com), a staging URL (http://mywebsite.stagingserver.com), and a local development URL (http://mywebsite.dev).
I'd like to use the same .htaccesss file/rules on the local, staging and live sites (so I can version control this file in multiple environments), so I was hoping that I could enforce the 'add www' rule only for the live site (as adding 'www' to the local or staging URLs breaks the site). So I've came up with this:
RewriteEngine On
# Add www
RewriteCond %{HTTP_HOST} !(mywebsite.dev|stagingserver.com)
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
It seems to work (as far as I can tell), but can anyone tell me of anything better than I could be using instead please?
Thanks,
Stephen