tags:

views:

118

answers:

4

I was looking for ways to mimic something I've seen, however I'm really not even sure where to start or how to search for it.

Lets say my page was:

foo.com/ and my index page could take an argument of: index.php?id=5

What I'm wanting to do is create the following:

foo.com/5/ rather than placing index.php?id=5 just use the webstring to pass in the parameters, to hide not only the fact its a PHP page, but to clean up the url a bit more.

Is this possible?

Cheers

+11  A: 

You'll want to look into URL rewriting. With the commonly used Apache webserver, this is accomplished with mod_rewrite.

ceejayoz
Just a note, though this is the correct answer for changing/masking the url. This won't hide the fact your using PHP completely, as the response headers will more than likely contain information about PHP.
MitMaro
Thank you. Got this working perfect after a little searching on mod_rewrite. Thanks again!
Frederico
+2  A: 

or /?5/123/ and in php parse the query string if rewrite is not available

n00b32
That's a nice one, where mod_rewrite is not available. **But** it depends on a `DirectoryIndex index.php` setting.
Boldewyn
+2  A: 

Something like this should suit:

RewriteRule ^pages/([A-Za-z_-]*)(/?)$ /index.php?page=$1

Broken down, we're looking for a URL that starts with pages, has any combination of letters, underscores and hyphens, and an optional trailing forward slash, and passing that to /index.php to handle.

Gav
That won't be very helpful without `RewriteEngine on`... or in IIS. :-)
ceejayoz
A: 

Yes Mod_rewrite is best option, you can create .htaccess file. if you do not want the write a custom function which will handle the your url.

santosh