1. Technology

Why Rewrite Your Web URLs

Creating Useful URLs is More Important Than You Think

By

URLs are a usability issue for many Web sites. Your URL might look like:

http://www.servername.com/ ~username/directory/file.html

Or:

http://www.servername.com/directory/ subdirectory/subdirectory/

Or they might be more complex like:

http://www.servername.com/index.jsp? cat=12&id=34&svr=56&hst=78

But no matter how you slice it, chances are your URL is not as easy for your customers to figure out as you might like. Now you might be thinking, "But my customers come to my site by links, so who cares if they can't figure the URLs out?" While on the surface this is true, in reality, your URLs can seriously impact your Web server in many different ways:

    Ease of Use

  1. Long URLs are harder to type
    This may seem obvious, but the reality is that most people type in URLs at one time or another. If your URL is really long, they won't be able to type it in (or at least not correctly) and so will get frustrated and not come back. You've lost a customer.

  2. Long URLs are also hard to paste
    If you've ever tried to copy a long URL and then paste it into an email message you'll know what I mean. Long URLs often get truncated by the email client (either yours or your recipients) and while they'll still often look clickable, they won't work. Just think, you've got a product for sale, and your customers want to tell their friends to buy it too, but they can't because your URL gets cut off in the email. You've lost a sale.

    Security

  3. URLs expose the guts of your site
    If you're using ASP or JSP or PHP, you shouldn't be telling your readers that. Just the fact that you're using one of thoese technologies opens your site up to hack attempts. And if the hacker succeeds, you've lost your credibility.

  4. The query string gives hackers more information
    When you then tack on a query string to the end of your URL, you tell the hackers what strings work as parameters to try front-door attacks on your server. When you get hacked, you've lost sales because your customers won't trust you with their credit information.

    Maintenance Issues

  5. If you decide to change your URLs in the future, all your URLs will break
    For example, right now, you might be using straight HTML, but you want to upgrade your site to JSP. When you do that upgrade, you have a choice, you can either let all your old pages break, leave them up getting staler and staler, or set up redirects for every page. If you don't do this you've lost customers either because the information was incorrect (if you left the pages up) or wasn't there at all.

  6. Switching to XHTML can be difficult
    This is primarily true if your URLs have punctuation in them. For example, the URL with the ampersands (&) will need to have all those ampersands escaped when put into an XHTML document, even when linking to the page. If you don't, you've lost standards based design.

What Can You Do?

The easiest thing to do, if you have an Apache Web server, is to set up a mod_rewrite or mod_alias on your server root. These two modules tell the server to look at the request as it's coming in and evaluate it. If it's pointing to a live page, then the server will serve the page. But if it's pointing to a page that needs to be rewritten or aliased, then it serves up the appropriate alternative page.

If you don't have Apache, or can't edit the rewrite and alias files, then you can use the meta refresh tag to set up redirects for the pages you want to redirect. This is a bit slower than using the mod_rewrite or mod_alias options, because you can't use regular expresssions. Instead you have to set up a redirect for every page individually.

  1. About.com
  2. Technology
  3. Web Design / HTML
  4. Web Server Management
  5. Web Administration
  6. mod_rewrite and mod_alias to redirect URLs in Apache: Why Rewrite URLs

©2014 About.com. All rights reserved.