Practical Ecommerce

6 Reasons to Use URL Redirects

A URL redirect is a mapping from one web page address to another. You can set it up on your web server or even in the source of a web page that you have created. You don’t need to be at technical whiz to run a successful ecommerce business, but redirects are one of those small technical issues that are important to understand and implement.

In this article, we will look at (a) the two primary types of redirects, (b) important reasons to use them, and (c) show you six examples. If you implement any of these examples, be sure to test your site right away. A simple syntax error in one of these rules can cause your website to stop working.

Types of Redirects

When we talk about redirects, we are referring to the numeric codes that a web server sends back to a user’s browser. The two main codes (there are several others, too) are:

  • 301 – The page has moved permanently.

  • 302 – The page has moved temporarily.

Use a 301 redirect when you want the search engines, or site visitors, to be aware that you have permanently moved a page (which includes most of the examples in this article). Conversely, use the 302 code if you are creating a temporary web page.

The examples in this article assume you are using the Apache web server, which has a powerful utility known as mod_rewrite to redirect and alter URLs. If Apache is set up in a standard way, you can create a simple text file with the name .htaccess and insert the examples that we have given below. Apache’s mod_rewrite utility requires the use of specific Apache commands, such as RewriteEngine, RewriteCond, and RewriteRule, among others. Apache explains all of these in its “URL Rewriting Guide.”

Many ecommerce systems have an interface to set up redirects so you don’t need to directly edit files on your server. If you are not using Apache, you can likely take these examples and do something very similar in your web server environment.

Note that all the examples in this article use a domain name “example.com.” Wherever you see that domain name, you will need to replace it with your actual domain name.

Let’s take a look at six real-world redirect examples.

Example 1: Moving To A New Domain

Whether you have decided to change your business name, realized that “OhMyGoshThisIsTheCoolestDomainNameIntheWorld.com” was a little too long for anyone to remember, or you were threatened with legal action because your domain name infringed on someone else’s copyright, you might find yourself needing to move from one domain name to another.

In this case, you want to do a global redirect of all the old pages to the new pages.

Put the following in your .htaccess file:

RewriteEngine On

RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

(You are out of luck if you let your old domain lapse and somebody else has taken it over. In that case, you will not be able to redirect traffic from the old domain to the new.)

Example 2: Forwarding Multiple Domains

Some people have acquired many domain names and want to make sure they all lead to the same location. This is another situation where you can put a permanent redirect in place to easily guide your visitors and the search engines to the proper address.

Put the following in your .htaccess file:

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]

RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

If you utilizing multiple sub-domains for specific reasons or have a secure server with different URLs than your main domain, you will want to test before unleashing this rule on your site. Remember, always thoroughly test any redirect changes to your site.

Example 3: Canonical URLs

Some search engine optimization purists feel that you need to tell the search engines which is the definitive URL for your website. And they have a very good point. Most websites work with a “www” version and “non-www” version, and the engines can get a little confused over whether these two different versions are the exact same site. This issue can be easily addressed by directing all traffic to a single URL, which is called a “canonical” URL.

The above rule for forwarding multiple domains will take care of this situation very nicely. Here it is again:

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]

RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

Example 4: Changing Pages or Organization on Your Site

As your business evolves, you will likely reorganize your website or switch to a new platform. If you have worked hard to gain high search engine placement, you will want to be sure to map the old URLs to the new ones. This is a critical time to utilize 301 redirects and let search engines, such as Google and Bing, know that your old pages have not disappeared.

Use the landing page report in Google Analytics (or a similar tool) to determine your most highly visited pages and make sure that you map those pages to a corresponding page in your new site structure.

You can either do some fancy footwork with mod_rewrite and regular expressions (predefined instructions, essentially) to write one compact “recipe” that maps URLs with a certain pattern to new URLs on your current site. (See “.Htaccess rewrites, Mod_Rewrite Tricks and Tips” for more on mod_rewrite recipes, tips and tricks.) Or, you can opt for building a simple list of old and new URLs.

Here is a mod_rewrite example that you can put in your .htaccess file:

RewriteEngine On

RewriteRule ^(.+).html$ http://example.com/$1.php [R=301,NC]

This will permanently send any page ending in “.html” to the corresponding page ending in “.php”.

Here are some simpler Apache redirects that you can insert in the .htaccess file:

Redirect Permanent /tastystuff.html http://www.example.com/toprecipes.html

Redirect Permanent /deliciousdrinks.html http://www.example.com/reallydeliciousdrinks.html

Redirect Permanent /yummydesserts.html http://www.example.com/delectablecheesecakes.html

Note the format of the Apache redirects, above, is to type “Redirect Permanent”, and then the old page name, and then the complete new URL.

Example 5: Simplifying and Tracking Display Ads

We have thus far been mostly looking at technical considerations for URL redirects. But here is a marketing consideration. If you are advertising in print, or even online with banner ads, you might want to track the ads’ responses. You can accomplish this by using specific URLs that you include (or link to) in your advertisements. Then, with a simple redirect, you can send the traffic from that specific URL to the home page or the appropriate page on your site. By first sending the users to the “special” URL, you will be able to track the traffic to that URL in your analytics program.

Put the following in your .htaccess file:

Redirect Permanent /home/dp1/dir-46/categoryid-23dft4567?display=435 http://www.example.com/holiday2010

Perhaps your ecommerce system just has gnarly URLs that don’t look very good when you are sending them out to people. Redirects are a simple way to give, or tell, people an exact page address without overwhelming them.

Example 6: Emergencies

Hopefully you have never been in this situation, but maybe you have gotten that fateful email to inform you that you put a typo in your email marketing blast to 50,000 customers and people are getting the dreaded 404 (page not found) error. No worries. A quick redirect line in your .htaccess file will send your customers to the correct web page.

Redirect /fallspercials.html http://www.example.com/fallspecials.html

Conclusion

With a little knowledge and experimentation, you can utilize redirects to help your users and the search engines find the correct pages your website. You might need to practice, but once you get the hang of writing redirects, they will be important tools in your webmaster arsenal.

Michael Stearns

Michael Stearns

Bio   •   RSS Feed


email-news-env

Sign up for our email newsletter

Comment ( 1 )

  1. frank65l November 16, 2010 Reply

    Any help for those who do not have access to the .htaccess fil, such as those on the Yahoo Merchant Solution platform? I have used meta redirects as this is the only way possible i can find.
    Thanks,