-1

Possible Duplicate:
How to: URL re-writing in PHP?
Rewriting an arbitrary number of path segments to query parameters

Currently, on my website (source world gaming), I use the $_GET method to display reviews/news articles. For example, "sourceworldgaming.com/reviews.php?id=40" will display review #40 in the database.

IGN doesn't do this. For example, they use http://www.ign.com/games/guild-wars-2/pc-896298 - with no $_GET[] needed. How is this done? Do they create an index for each individual game?

I want to be able to make the URL sourceworldgaming.com/reviews.php/40

Also, would doing this make my site more search engine friendly? Thanks.

Community
  • 1
  • 1
  • 1
    Not sure exactly how they are doing it, but in general, [mod_rewrite (or similar)](http://httpd.apache.org/docs/current/mod/mod_rewrite.html) is your friend. – steveax Aug 18 '12 at 00:47
  • @mario dup of MANY a questions here. A little tip the the OP they are called pretty URLS – Cole Tobin Aug 18 '12 at 01:05

2 Answers2

2

Its done with mod_rewrite and the router part of the script:

The url: http://www.example.com/games/guild-wars-2/pc-896298

Is actually passed to the script like:

http://www.example.com/?route=/games/guild-wars-2/pc-896298

By using mod_rewrite (example)

RewriteEngine On
Options -Indexes
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?route=$1 [L,QSA]

Then basically /games/guild-wars-2/pc-896298 is split up into pieces using

$route = explode('/',$_GET['route'])

So $route[0] would be the controller or query the categories. $route[1] would be the action or query the game because $route[0] is a game category ect

Lawrence Cherone
  • 46,049
  • 7
  • 62
  • 106
0

The fact that requests for /foo.php go to a file named foo.php on your server is just an implementation detail. There's nothing about the web that requires this, it's just something that a lot of systems do, including PHP. Lots of other systems use different conventions, such as routing tables or object traversal.

If you've already built a website that uses the file system to route requests, the easiest way of getting different URLs is to use mod_rewrite or its equivalent on whichever web server software you use.

Jim
  • 72,985
  • 14
  • 101
  • 108