Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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

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]
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 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 at 17:41
1  
I was unaware of that, thank you for the correction –  Liam Sorsby Jan 30 at 17:44
    
@user2398188 In answer to your comment, you don't need the quotes around the RewriteRule object. –  dan Jan 31 at 2:48

Your Answer

 
discard

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.