1. Home
  2. Backup, Security & Performance
  3. SSL & Signing Certificates
  4. How to set redirection of www Or non-www in cPanel
  1. Home
  2. Backup, Security & Performance
  3. SSL & Signing Certificates
  4. How to set redirection of www Or non-www in cPanel

How to set redirection of www Or non-www in cPanel

1.   Using cPanel to Redirect 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.

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 differ 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 drop down.
  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 www or non-www

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

Redirect to www

  1. <IfModule mod_rewrite.c>
  2. RewriteEngine on
  3. RewriteCond %{HTTP_HOST} ^domain\.com [NC]
  4. RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
  5. </IfModule>

Redirect to non-www

  1. <IfModule mod_rewrite.c>
  2. RewriteEngine on
  3. RewriteCond %{HTTP_HOST} ^www\.domain\.com [NC]
  4. RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]
  5. </IfModule>

 

Updated on April 15, 2020

Was this article helpful?