Loading...
Loading

A Complete Guide to Create 301 Redirects in htaccess

2010-07-05by Sophia Carcia

Basics about Web Page Redirect

On a website, redirect is a technique for moving visitor from one web address to another different web address. There are many different reasons that a website may need redirect.

a) The website is at a similar but distinctly different domain name

b) Two websites are merging into one page

c) There is a completely new address for the website

For example, if a company has just changed its named then they would like to turn their visitors as well as customers to their new web page with the new name included.

These days, with the popularity of online affiliate marketing, web users often encounter redirection when they visit a selling link. This is because an affiliate link that looks long and scary is not friendly for online promoting. It is a common practice that the affiliate redirects an affiliate link to another friendly looking URL with the purpose of hiding the fact that they are sending a user to an affiliate offer.

If you have the necessity to redirect your webpage for whatever reason, this article is written for you. In this article, we will introduce the most efficient method for webpage redirect, 301 redirect, to help you out.

What is 301 redirect?

When redirecting a web page to another, one critical issue is to make sure the high search engine rankings with that page will not lose after the redirection. A 301 redirect is just this type of redirection, which allows you to preserve your current search engine rankings when redirecting web pages. 301 redirect is different from 302 redirect and it is a method to move your web pages permanently and there will no longer be any connection between the old address and the new URL address. You implement the 301 redirect by creating an .htaccess file (check with your hosting provider if they provide). What is an .htaccess file?

In web servers (usually Apache), .htaccess is the default name of a directory-level configuration file that allows decentralized management of web server configuration. An .htaccess file is a simple ASCII file, such as you would create through a text editor like NotePad or SimpleText. The .htaccess file contains specific instructions for certain requests, including security, redirection issues and how to handle certain errors. When a visitor or a spider make a request to your web page via any method, your web server need to check an .htaccess file firstly. Any changes made in .htaccess files will take immediate effect.

How to Implement a 301 redirect for static pages?

First of all, you need to check whether there is an .htaccess file in the root director of your server or not. If you have not found the .htaccess file, open notepad or similar application to can create a file, then name and save it as .htaccess.

If you already have an .htaccess file with some lines of code there, you simply need to download it to your desktop for editing. You should not make any changes to the existing codes unless you are familiar with the functions of the file.

Scroll down past all the existing code, leave a line space, and then create a new line to place the following code: redirect 301 /old/old.htm http://www.you.com/new.htm Save the file and then upload it to the root folder of your server. Turn on your browser and enter the old address of your web page you will find out that it is redirected to your new address. Congratulations to you!

Notes: Be sure that the old path of your webpage here start from the top level of your website to the old page, you should not add "http://www" at the beginning of your old address. In addition, you should keep a single space between the following three elements: redirect 301 /old/old.htm http://www.you.com/new.htm

How to Implement a 301 redirect for dynamic pages?

Different from the normal static web page, a dynamic page can change every time it is loaded (without you having to make those changes) and they can change their content based on what users does, such as clicking on an image or something else. Dynamic web pages usually generated by a database driven application, such as blog or forum software. That means that the web page will grab information from a database and inserts that information into the web page every time it is loaded. When looking for the URL address of a dynamic web page, you will see that there is a file name appended by a query string, similar to the following: http://www.example.com/page.php?id=13

If there is a query string in your old URL address, we can say that your web old web page is a dynamic one. If this is the case, then the above 301 redirect solution for static web pages will not fit your purpose. Instead, you are required to use a rewrite solution. Take the above address page.php?id=13 for an example, you will need to all following codes in your htaccess file:

RewriteEngine on RewriteCond %{QUERY_STRING} ^id=13$ RewriteRule ^/page.php$ http://www.example.com/newname.htm? [L,R=301] Please remember to replace the above the id=13 with the query string of the page you wish to redirect and also replace the page.php with the name of your file prior to the query string.

How to Implement 301 redirect for file names with spaces?

Once I had take over a website that built by someone who really not good at his job. I found out that most of the web pages had file name with space, such as "Ticket Order Form.htm". I would like to redirect these old pages to the new, properly named pages, then I got into trouble with a standard redirect 301 codes. Fortunately, I finally got it function perfectly when someone telling me to use quotes around the original file path. Well, it should look like: redirect 301 "/old page.htm" http://www.example.com/newpage.htm

How to Implement 301 redirect for the entire website? If you have found an ideal new domain name for your company and expect to make advantage of the new domain name because it is so wonderful, then you can simply redirect the entire website by adding the following code to .htaccess file. redirect 301 / http://www.you.com/

The first slash "/" implies that everything from the top level of the site down will be redirected. If you are going to use the same paths and filename as the old one, it is fairly easily to achieve your purpose with this method.

Please not forget to have the trailing "/" on the destination URL, or it may not function correctly. Also, when redirecting a domain name with 301 redirect, you are recommended to leave the old domain name and files in place for a few weeks to give the search engines time to index your changes.

Do you need to make any redirection for your web pages? It is not that hard as you imagine, isn't it? You can finish the whole process of redirects within a few seconds if your hosting provider offers you with cPanel hosting and .htacess file.

news Buffer
Author

Sophia Carcia

Hostease

Hostease is a leading web hostingcompany, who offers REAL 24/7 support via email, live-chat and phone forclient's satisfaction. We never overload our server. All of our plansinclude the latest industry features available on the market. We caterfor the personal blog as well as the multiple websites for largebusiness group. Our packages are equipped with the features needed tomeet all of your requirements.

View Sophia Carcia`s profile for more
line

Leave a Comment