3

I know how these kind of URLs load the page ... based on their GET parameter.

http://www.bedupako.com/songs.php?page=show_song_details.php&songid=1167&n=0&back=no

and in the back-end roughly something like this:

<?php
switch($_GET['page']) {
case 'xx': include('my page');break;
.
.
.
default: include('default');break;
}
?>

But how do these kinds of URLs work? I mean, how is the data loaded dynamically?

www.dummysite.com/parm/subpage1/xyz
www.dummysite.com/parm/subpage2/xyz

How are these parsed similar to the GET param like websites?

footy
  • 5,803
  • 13
  • 48
  • 96

3 Answers3

2

In most cases this will be handled by the web server on-the-fly according to a set of rules. The specifics of it will vary from server to server and on a case-by-case basis. In Apache it is usually done using the mod_rewrite extension.

EdoDodo
  • 8,220
  • 3
  • 24
  • 30
1

You should look at http://httpd.apache.org/docs/2.0/misc/rewriteguide.html url rewriting if you're with apache (most likely)

yokoloko
  • 2,820
  • 3
  • 20
  • 27
1

You can use mod_rewrite by itself as others have suggested, but most sites do not do this because its not very flexible, and can be annoying to maintain if you have more than a couple of these "pretty" URLS.

Instead they set up a basic rewrite rule to forward everything to a single index.php and then on the application side they parse the URI based on defined patterns - these are called "routes". Route parsing usually happens in some kind of routing class which process the defined routes and compares them to the URI, and then when it finds a match parses out the parameters for the matched route.

These all provide good examples of a router, but they are hard to understand without the other interacting classes:

prodigitalson
  • 60,050
  • 10
  • 100
  • 114