Managing redirects via .htaccess

May 3, 2016

This post may be a little more technical than most but it’s a very useful bit to know that will help you get better SEO results. A permanent 301 redirect in your .htaccess file lets search engines and others know that an old link has been replaced by a new one. It’s the recommended method for directing traffic from an existing page. An example of when you might want to use this would be when you’ve made a new website on a subdomain (or where the root of the site is in a new folder) so that when you want to go live you add this redirect.

Some common uses of a 301 .htaccess redirect:

• Redirect individual files on the same domain
_ Why? –> An old file has moved locations, or the information is now contained in a new file.

• Redirect an old domain to a new domain
_ Why? –> You’ve moved a website from an old domain to a new one, and you want any old links to go to the new site.

• Redirect all files with certain extension
_ Why? –> You used to have all of your files using an extension like .php and have converted everything to .htm so using a 301 redirect you can update all links to use the new extension.

 

OK, so let’s get started:

By following the steps below you can modify your .htaccess file by way of using the File Manager in your hosting control panel here:

Screen Shot 2015-07-19 at 7.51.40 PM

Then Locate your .htaccess file, if you don’t have one, you can make one by selecting:(plus) New” –> “Create New File

Screen Shot 2015-07-19 at 7.59.02 PM

Now, right click on it and select “Edit in Text Editor

Screen Shot 2015-07-19 at 7.56.34 PM

Now you want to add your redirect, the format has 3 parts:

1. “redirect 301” (This won’t change)
2. The old location (In many cases it’s “/” or the root of the site)
3. The new location (This can be almost anything)

Here are a few Examples:

redirect 301 /oldpage/ http://www.yournewsite.com/newpage/
redirect 301 / http://www.yournewsite.com/
redirect 301 /oldpage.html http://www.yoursite.com/newpage/

Note: If you’re forwarding an entire domain to another, the simplest way to do this is to simply add it as a domain alias –> The server control panel will automatically ensure that it sets up a 301 redirect for you.

Note: If you are looking to redirect your WordPress installation so that when people go to your domain they are automatically forwarded to the subdirectory where you’ve installed WordPress you can add this to your .htaccess file:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?YOURDOMAINNAME$
RewriteRule ^(/)?$ YOURSUBDIRECTORY [L]

(where you replace YOURDOMAINNAME with your domain name & YOURSUBDIRECTORY with the subdirectory WordPress is installed in)