How to do 301 Redirects in .htaccess – Apache
301 redirects are a search engine friendly way to redirect an old or un-used page to a new page, file or domain. 301’s are a vital part of search engine optimization because they allow you to pass page rank from an old page or domain without losing the page rank of the current url. This is very important when redirecting older pages or sites that have collected lots of “equity”.
Adding 301’s to .htaccess
There are many different ways of permanently redirecting urls to a new domain or page, but today I am going to show you how to do it through your .htaccess file.
I personally prefer using the .htaccess file for all of my redirects, as opposed to using a 3rd party WordPress plug in that may or may not go out of date or have issues down the road.
Step 1: Backup
Before making any changes in the .htaccess file make sure you download the original as a backup copy just in case anything goes wrong. The .htaccess file provides a vital role in how your website functions and one piece of wrong code could cause the site not to display properly.
Step 2: Writing the Redirect
Identify the old page that you want to redirect, then create or find the new domain, file or page that you want it redirected to. Once you have that the rest is fairly simple.
The first part is identifying the type of redirect you would like to perform. 301’s are a “permanent” redirect and pass page rank to the new url.
The next step is to type out the relative url of the old page. A relative URL is just the file path, without the domain name, ex. /file-name.html.
Next is to type the new site or page you will be redirecting to. This URL is an absolute URL, meaning it contains the domain name as well as the URL path.
Make sure there is one space between each segment.
See the graphic below for more clarity.
Congratulations! You have just written your first 301 redirect!
Step 3: Adding a 301 redirect to the .htaccess file
This next step is very simple but can also be very delicate, depending on how large your .htaccess file is.
Below is the typical .htaccess file for a WordPress site. All you have to do is copy and paste the 301 redirect into the beginning of the file, save, upload back to the root and you’re done!
Be sure to test the redirect by trying to navigate to the old page, if it works you will be redirected to the new page!
I hope this has been an infomative and helpful walkthrough, if you think I missed something or would like more information, please send me an e-mail, info@eclipsewebmedia.com, or connect with me on Twitter or Google Plus.
By: Blueprint
The comments are closed.
No reviews yet