Trouble redirecting non www urls to www

I’m trying to make non www urls to my site redirect to www urls. When I place the command below (replacing with my actual domain of course) in the .htaccess my site cannot be accessed at all.

RewriteEngine On
RewriteCond %{HTTP_HOST} !^$ [NC]
RewriteRule ^(.*)$$1 [L,R=301]

My hosting service told me to try this one and it caused a 500 error.

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^[nc]
RewriteRule ^(.*)$$1 [r=301,nc]

Any ideas on what could be causing this?

Try this:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\\.mysite\\.com$ [NC]
RewriteRule .?{REQUEST_URI} [R=301,L]

You are a genius! You just did what my hosting provider couldn’t do in two days and several attempts. Thank you very much.

Ha ha, no, I’m a copy-pasta dolt. :smiley: I just copy the code the geniuses like @dklynn around here post. But glad to be of assistance. :slight_smile:

If that’s true then my hosting provider should hire some “copy-pasta dolts”. :slight_smile:

Thanks again.

Yes, perhaps email them and suggest they sign up to a forum. :lol: