Htaccess 301 Redirect

Redirecting a web page from one URL to another is best achieved using a HTTP redirect. You may want to perform a redirect after changing the URL of a page and you want existing links to the old URL to remain valid. In this tutorial, we look at how to do an htaccess 301 redirect.

If a search engine has indexed a particular page and sends traffic regularly to that URL, then simply moving the page to another URL will cause that search engine traffic to be directed to a 404 Not Found error. To fix this problem, we rename our URL and then use a 301 Redirect to instruct browsers and search engine spiders that the page which was at the old URL has now moved.

It is possible to use a HTML Redirect (Meta Refresh) with a timeout of zero to perform the redirect but this is not the optimal way as a similar technique has been used in the past to manipulate search engine rankings. Spammers have used sneaky redirects to manipulate the flow of traffic, so using the meta refresh technique is usually ill-advised in terms of SEO.

htaccess Redirect Example

To instruct Apache to perform a redirect when a particular page is requested, we need to place an instruction in our .htaccess file. This is the htaccess 301 redirect instruction. This .htaccess file should be placed in our document root to ensure that the redirect happens site-wide.

For example, to redirect from "/oldpage.htm" to "/newpage.htm" we would add the following to our .htaccess file:

redirect 301 "/oldpage.htm" "newpage.htm"

It is as simple as that, just place the name of the URL to redirect from as the first parameter after the 301 code, and the name of the URL to redirect to as the second parameter.

To redirect a page to an entirely new site is also straightforward:

redirect 301 "/oldpage.htm" "http://www.example.com/newpage.htm"

Redirect an Entire site with htaccess

To redirect an entire site using .htaccess is also very simple.

You simply use:

redirect 301 "/" "http://www.example.com/"

The first slash (/) tells Apache that everything from the top level of the site should be redirected. Redirecting an entire site is useful in a situation where you have changed your domain name and want to redirect all traffic to the new URL, regardless of the page which was requested at the old URL.

We hope this tutorial on htaccess 301 redirection was helpful.

Thank Tutorial Arena for This Tutorial.
Show your appreciation with a +1...