Wednesday, October 15, 2008

Simple 301 redirect in .htaccess for apache

As a webmaster looking at my "Not Found" links under Web Crawls section of Google's Webmaster Tools I noticed there were dead links. I had already gone through my entire site to make sure there weren't any dead links but for some reason Google was finding dead links. Then it struck me, this was a domain that we purchased from someone else. The dead links were incoming links to pages that no longer existed. I want those incoming links but don't want to have to contact the webmasters of the websites with the incoming links and tell them to change their links. Even if I did, they may not change the links anyway (and what if its an old blog post from some long gone user)?

A "301" redirect is telling search engines that a page or file has permanently moved. This is good for SEO (Search Engine Optimization).

In comes your .htaccess file. A simple 301 redirect telling the browser, robot, spider or whatever that page A is now page B. Here is how:

Add a line in your .htaccess file like this:
Redirect 301 /oldpage.htm http://www.WEBSITE.com/newpage.html

Thats: "Redirect" [space] "301" [space] "/" (directory)"File"(old page thet you want to redirect) [space] "New File" (the new destination page)

This makes it so that when some goes to WEBSITE.com/oldpage.htm they are redirected WEBSITE.com/newpage.html.

You get to keep that incoming link without having to ask someone else to update their code or having to create a page with that exact page name then do a meta refresh (I don't like those anyway).
Post a Comment