I'm switching servers and need to change the following RewriteCond and RewriteRule commands in the .htaccess file.

Right now I'm pointing domain.com to www.domain.com using:

RewriteCond %{HTTP_HOST} ^domain.com$
RewriteRule ^(.*)$ "http\:\/\/www\.domain\.com\/$1" [R=301,L]

I need to switch the commands and do the opposite, where I point www.domain.com to domain.com.

1 Answer 1


You just need to change the URL structure in the same two lines:

RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]
  • you need to escape your www.domain.com to www\.domain\.com and with the one below. Still a simple nice answer Jan 30, 2014 at 17:16
  • Thanks. It's only suggested to escape metacharacters in the regular expressions of a RewriteRule, but not the target. See Regular Expressions here.
    – dan
    Jan 30, 2014 at 17:41
  • 1
    I was unaware of that, thank you for the correction Jan 30, 2014 at 17:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.