I'm switching servers and need to change the following RewriteCond & RewriteRule commands in the .htaccess file.
Right now I'm pointing domain.com to www.domain.com

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.
I would appreciate some help with the syntax. Thank you

Recommended Answers

All 3 Replies

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

Have you tried simply swapping out where the www is?

OK, I'll try this. Are you sure this is the right syntax.
I'd rather not experiment, since I'm following specific instructions from my host provider and at some point loose access to the VPS that I'm adding this code to.

I might be wrong about escaping the http:// part. I removed the double quotes that you had b/c I had never seen that before. This should work:

RewriteCond     %{HTTP_HOST}    ^domain.com$                [NC] 
RewriteRule     ^(.*)$      http://www.domain.com/$1        [R=301,L] 
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.