You are currently viewing Best Ways to Redirect www or non-www
non-www Redirect to www htaccess

Best Ways to Redirect www or non-www

Developing your website on www or non-www URLs may be for beautiful reasons, particular decision or to prevent unnecessary hostnames. It is advised that you keep the hostname of your website the same everywhere. Either with the www part or without the www part. Redirect www or non www

In WordPress, you have a home URL and site URL so the unnecessary host names issue is not a problem since WordPress will automatically redirect to ensure that the site is running on the same site URL as it should be. Other applications may require your attention in this area though. Google Analytics will also give you a “Redundant Hostnames” warning if you don’t. You want to do a permanent, HTTP 301 redirect for this.

redirect www or non www
redirect www or non www

How to Redirect to www or non-www

There are two quick and easy ways of doing this on our servers. Pick one of the two methods that you prefer to use. The first one is the easiest for most users.

1. Using cPanel to Redirect to www or non-www

This is easy to do with cPanel. Login to your cPanel to get started. Go to Domains > Redirects on the cPanel main page. Now depending on whether you prefer the URLs with the www part or without the www part, the instructions will change a bit.

Redirect to www

  1. Set the type to permanent which will give an HTTP 301 status code.
  2. Choose your main domain in this dropdown.
  3. Leave the path empty, you want to redirect the entire domain.
  4. Specify the URL to redirect to with the “www” part in it.
  5. Choose “Do Not Redirect www“.
  6. Leave the “Wild Card Redirect” unchecked.

Redirect to non-www

  1. Set the type to permanent to give a 301 HTTP status code.
  2. Select the main domain from the drop-down menu.
  3. Leave the path empty, we want to redirect the entire domain.
  4. Set the URL to redirect to without the “www” part in it.
  5. Choose “Only redirect with www“
  6. Leave the “Wild Card Redirect” unchecked.

2. Using .htaccess to Redirect to www or non-www

Just put the following lines of code into your main, root folder .htaccess file.
In both cases, just change out domain.com to your hostname.

Redirect to www


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

Redirect to non-www


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

Latest Posts


Leave a Reply