How to 301 redirect www to root?

Hello!
I can’t beleive how painfully difficult it is to find a simple 2-liner answer to a simple question:

I need to redirect requests that come to www.mydomain.com to mydomain.com

I am sure there is a simple 1-3 lines of code in httpd.conf that can do that. Instead when Googling for the answer, I keep seeing a long essays about 301 redirects but no real-world workable solution!
It’s like everyone wants to write a long article about it, probably for seo purposes but nobody wants to just say, here, this is how you do it:… done!

Can someone please just tell me the what to add to httpd.conf

my new site is http://www.qod.tw

I don’t want people to use the www part, so all traffic should be redirected to the http://qod.tw

Thank you.

The setting to do that redirection should be found in your Host Control Panel.

I am with DreamHost so I got the option. Check to see if you got it too.

This starting to be funny. All lectures but no real answers. What If I don’t have a control panel? Then what?

http://vision-media.ca/resources/seo/301-redirect-with-no-www-using-htaccess

I tried this one
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]

but then when someone what typing www.qod.tw
it was redirecting to www.qod.tw//
It was adding an extra / at the end
and when typing www.qod.tw/make
it was redirecting to http://qod.tw//make
another extra slash.

I just changed that rule to
RewriteRule ^(.*)$ http://qod.tw$1 [R=301,L]

So now it seems to be working.

lamp,

Did you bother to look at the sticky threads? Did you bother to look at the tutorial linked in my signature? The code is there! Sorry, I get SO frustrated at the lack of “minimal effort” by posters asking simple questions.

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

WILL, as you discovered, redirect to http://qod.tw//. While

WILL give you the answer you want (on Apache 2.x), it’s still not (universally) correct.

RewriteCond %{HTTP_HOST} ^www\\.god\\.tw$ [NC]
RewriteRule .? http://god.tw%{REQUEST_URI} [R=301,L]

WILL take care of the problem MOST EFFICIENTLY on either version of Apache.

Regards,

DK