Web Hosting Forum - A Web Hosting community for Webmasters


Divi WordPress Theme

Author Topic: URL Rewriting - Get Rid of Those Ugly Dynamic URLs  (Read 4163 times)

0 Members and 1 Guest are viewing this topic.

Offline Tech

  • Junior Guru
  • **
  • Posts: 183
  • iTrader: +2/-0
    • View Profile
URL Rewriting - Get Rid of Those Ugly Dynamic URLs
« on: September 09, 2007, 10:47:07 AM »
Have you searched forums about dynamic URL rewriting and come out more confused than when you went in? This article aims to make clear the "groundwork" of URL rewriting. More resources will be pointed out to further your understanding and get you actually doing it!

If you're reading this article, you probably know that Search Engines do not index dynamic URLs as well as they index static URLs. The most popular method of automatically rewriting URLs is called "mod rewrite". If you are using an Apache server to host your website(contact your web host) then read on. If not then have a look at the mod rewrite article in Wikipedia and read no further.

The simplest way to do a mod rewrite with an Apache server is to upload a text file named .htaccess to your root folder (where your imdex.html file is stored) that contains certain rules. That said before we go any further you need to understand how mod rewrite works.

How does Mod Rewrite for Apache work?
What mod rewrite does in its simplest form is take a static URL that you type in, for example http://www.africapic.com/index/closeup/100-3976-0.html and treat it the same as if you had typed in a dynamic URL, for example http://www.africapic.com/index.php?page ... 76&start=0 (take note now that the numbers correspond). In other words, the second URL is actually fetched but the location bar displays the first URL. Search Engines will now understand the page as static not dynamic – hooray! Please Note: you still have to change the internal links of your site to point to the new static URLs not the old dynamic URLs (see below). For the example above this would require a knowledge of PHP.

So how do you do it?
Firstly, you need to have knowledge of "Regular Expressions" for mod rewriting. Regular Expressions is a programming term that is "a string used to describe or match a set of strings" (Wikipedia). For example, the regular expression [^/]+ would match with "any string of characters up until the '/' ". For more information goto http://forum.modrewrite.com/viewforum.php?f=12.

Secondly, once you know how to use regular expressions for mod rewrite, you need to decide which dynamic URL you want changed and what it'll look like when it is changed. In the example above you can see that the pageId, id and start values remain the same in the static URL, this is very important as when the static URL is changed to a dynamic URL on the server (see below) the values are taken from the static URL.

Thirdly, you need to write rules and put them in a text file named .htaccess (that's [nothing].htaccess). What these rules do is use regular expressions to match a static URL. If the match is correct (for e.g. match a number then a "-" then a number then a "-" then a number.html) the rule rewrites it as a dynamic URL on the server (the browser location bar still shows a static URL). There are many technical things to remember when doing this so why not have a look at the forum mentioned above. The .htaccess file is then uploaded to the root folder of your web page (same folder as the index.html file would go).

Lastly, you need to change the internal links of your site to point to the new static URLs not the old dynamic URLs.

Conclusion
To conclude for doing a mod rewrite when you have an Apache server you need to know how to program regular expressions, you need a clear understanding of what URL will be seen by the user and what URL is accepted and displayed by the server and you need the technical know how of writing rules in an .htaccess file.

http://www.africapic.com

Article Source: http://EzineArticles.com/?expert=Samuel_Moore
« Last Edit: January 01, 1970, 05:30:00 AM by Tech »

Divi WordPress Theme
Tags:
 

Related Topics

  Subject / Started by Replies Last post
0 Replies
2705 Views
Last post September 09, 2007, 10:44:37 AM
by Tech
0 Replies
3964 Views
Last post November 16, 2008, 10:37:33 AM
by Kailash
0 Replies
807 Views
Last post March 20, 2015, 11:07:23 PM
by Kailash