GICT knowledge base
Redirect domain.com to www.domain.com and vice versa
Published
In this documentation, we can check how to redirect domain.com to www.domain.com and redirect www.domain.com to domain.com. We can do this by adding the rewrite rule in the .htaccess file. ( It is also possible to do the same by using cPanel Redirect tool. More details of that method is available here )
We can use the following steps to do this.
1) Go to the home directory.
cd /home/username/public_html
(Replace the username with the exact username).
If you are not using cPanel server, go to your home directory.
2) Open the .htaccess file.
vi .htaccess
Or use your favorite text editor like nano
3) Add the following lines in .htaccess file and save the file.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
(Replace domain.com with your exact domain name).
There is no need to restart apache.
From now onward, when someone access your domain.com will redirect to www.domain.com.
Same as we can redirect www.domain.com to domain.com using the following steps.
1) Go to the home directory.
cd /home/username/public_html
(Replace the username with the exact username).
If you are not using cPanel server, go to your home directory.
3) Open the .htaccess file.
vi .htaccess
4) Add the following lines in .htaccess file and save the file.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.domain.com [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]
(Replace domain.com with your exact domain name).
There is no need to restart apache.
From now onward when someone access your www.domain.com will redirect to domain.com.
That is how we can redirect domain.com to www.domain.com and redirect www.domain.com to domain.com.
If you need any further help please reach our support department.
Related guides
Host Additional Domains on an Eligible InterServer Account
Check your hosting limits, choose a separate site or alias and use cPanel or DirectAdmin with deliberate DNS, content and certificate verification.
cPanelHardening Your cPanel Server: Beyond the Basics After CVE-2026-41940
Security is a moving target. With the recent discovery of CVE-2026-41940, it has become clear that just having a firewall isn't enough anymore.
cPanelcPanel and Plesk notice: Awstats,. Webalizer and Analog stats are being removed
Important Update: cPanel and Plesk Phasing Out Legacy Statistics Tools If you regularly check your website traffic through your hosting control panel, we have an...
cPanelThe dangers of shared licenses (in other words unofficial/cracked licenses)
Why Cracked cPanel Licenses Aren’t Worth the Risk: A Guide for InterServer Customers When you’re managing a server, every dollar counts.

