Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

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]
share|improve this answer
you need to escape your www.domain.com to www\.domain\.com and with the one below. Still a simple nice answer – Liam Sorsby Jan 30 '14 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 '14 at 17:41
I was unaware of that, thank you for the correction – Liam Sorsby Jan 30 '14 at 17:44

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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