How to Set Up a 301 Redirect with an .htaccess File

A 301 Redirect enables you perform certain tasks including:

  • Redirect the old URL of a web page to the new one
  • Redirect website pages from an old domain to a new one
  • Force all HTTP requests to HTTPS
  • Consolidate duplicate pages that compete for the same keywords into one page
  • Redirect a deleted page to another relevant page or your homepage

301 redirects on our shared hosting are performed using Apache's mod_rewrite module. You can enable them by editing (or creating) the following in your .htaccess file:

<IfModule mod_rewrite.c>
RewriteEngine On
</IfModule>

You may then proceed to add rewrite rules below "RewriteEngine On." The rules you add will depend on what exactly you want to redirect. 

Common Examples

Redirecting a Single URL

Redirect 301 /old-page/ https://www.yourdomain.com/new-page/

Redirecting a Single Folder

RewriteRule ^/?blog/(.\*)$ /news/$1 [R,L]

Redirecting WWW to Non-WWW URLs with a 301 .htaccess Redirect

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

 

More examples can be found in our "Apache mod_rewrite and examples" article.

 

 

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Monitor the servers's status

This can be done in cPanel, in the left hand menu. Scroll to the bottom and find the link for...

What are my nameservers

Not sure what the names servers are for your website's domain name? Kindly refer to the welcome...

How do I add another domain to my Account?

Some DT shared Linux web hosting plans allow you host multiple domains on the same account. To...

How do I manage my Shared hosting account?

We offer cPanel to manage your Shared Web Hosting account. You can learn more about cPanel here

How Do I Create and Remove an Addon Domain?

An addon domain is a fully functional domain that can be created from within your control panel....