Redirect www URLs to non-www

In order to redirect all requests for www.yourdomain.com to yourdomain.com, you should set the appropriate rewrite rule. This can be done by adding the following lines at the beginning of the .htaccess file in your public_html folder:

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

When someone accesses http://www.yourdomain.com s/he will be redirected to http://yourdomain.com.

Using this method is safe because it should not create any redirection loops nor it should interfere with other rewrite rules.

Was this answer helpful?

 Print this Article

Also Read

Updating DNS at StarGate.com

This demo assumes you have a domain name registered through StarGate.com, and starts from the...

PHP and HTML redirects

If you do not wish to use the .htaccess file to redirect your visitors, you can use another...

Updating DNS at NameBargain.com

This demo assumes you have a domain name registered through NameBargain.com, and starts from the...

Updating DNS at DomainSite.com

This demo assumes you have a domain name registered through DomainSite.com, and starts from the...

URL Masking with .htaccess

In case you would like to access a certain URL for your domain name but do not display it in the...