1

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.

2

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]
|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
  • 1
    I was unaware of that, thank you for the correction – Liam Sorsby Jan 30 '14 at 17:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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