I created a website and I would like when I put any link pointing to my website, the "www" to be removed.

For example when someone enters http://www.mydomain.com/users into the browser address, this to be changed into http://mydomain.com/users when the page loads up.

I have seen this happening with twitter. if you try to go to http://www.twitter.com/john it will automatically remove the "www" and change the address to http://twitter.com/john .

However, this does not happen for http://www.facebook.com/john.

I am not sure if this have something to do with the domain's configuration (CNAME record?) but any point / tip to the right direction will be really appreciated!

2 Answers 2


You can use a simple HTTP redirect to remove the "www". Twitter for example uses a HTTP 302 (Moved temporarily) redirect to point http://www.twitter.com to http://twitter.com (and then a HTTP 301 (Moved permanently) to redirect to https://twitter.com).

Depending on your web server, there should be configuration options for this. In Apache, for example, you'd add the following to your .htaccess file:

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

This is something that has to be configured in your host.

If you are using Apache for example you could add a couple of lines to the .htaccess file:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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