1. Home
  2. How To
  3. Shared Hosting
  4. Linux Hosting (CPanel)
  5. How to do URL redirection using .htaccess

How to do URL redirection using .htaccess

Issue

Unable to redirect web site traffic from your old pages to the new pages without losing your rankings

Symptoms

None

Cause

Lack of knowledge on performing redirection using .htaccess

Workaround

Redirect Old domain to New domain (htaccess redirect)

Create a .htaccess file with the below code, it will ensure that all your directories and pages of your old domain will get correctly redirected to your new domain. The .htaccess file needs to be placed in the root directory of your old website (i.e the same directory where your index file is placed)

Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.yournewdomain.com/$1 [R=301,L]

Please REPLACE www.yournewdomain.com in the above code with your actual domain name.

Note: This .htaccess method of redirection works ONLY on Linux servers having the Apache Mod-Rewrite moduled enabled.

Redirect to www (htaccess redirect)

Create a .htaccess file with the below code, it will ensure that all requests coming in to yourdomain.com will get redirected to www.yourdomain.com The .htaccess file needs to be placed in the root directory of your old website (i.e the same directory where your index file is placed)

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^yourdomain.com [nc]
rewriterule ^(.*)$ http://www.yourdomain.com/$1 [r=301,nc]

Please REPLACE yourdomain.com and www.yourdomain.com with your actual domain name.

Note: This .htaccess method of redirection works ONLY on Linux servers having the Apache Mod-Rewrite moduled enabled. 

Additional Information

If the problem still persist, kindly issue a ticket to Support Team

Updated on September 26, 2018

Was this article helpful?

Related Articles

Leave a Comment

Need Help?
Submit a ticket to us and let our professional team assists you

Support Billing Sales
Support
Billing
Sales