I'm having trouble redirecting non-www to www in htaccess.
The goal is to have non-www URLs (with or without subfolders) for a particular domain (domain1.co.uk) redirect to their www equivalents.
So:
'domain1.co.uk' should redirect to www.domain1.co.uk
and
'domain1.co.uk/subfolder' should redirect to www.domain1.co.uk/subfolder
I've tried a couple of things, each with undesired results.
Attempt #1:
RewriteCond %{HTTP_HOST} ^domain1.co.uk [NC]
RewriteRule ^(.*)$ www.domain1.co.uk/ [L,R=301]
Result #1: non-www URLs with subfolders redirect to the homepage (so it's impossible to access any subfolders without including 'www' in the URL)
Attempt #2:
RewriteCond %{HTTP_HOST} ^domain1.co.uk [NC]
RewriteRule ^(.*)$ www.domain1.co.uk/$1 [L,R=301]
Result #2:
'domain1.co.uk/subfolder' redirects to www.domain.co.uk/subfolder (as desired)
but 'domain1.co.uk' now redirects to www.domain.co.uk/www/ (strange result)
Any idea what might be happening here?
I'd be happy to post the full content of the .htaccess file if that would help.