views:

62

answers:

3

I dont like something like this: example.com/?id=2222. How to change it into example.com/2222?

+8  A: 

You need to look into mod_rewrite.

From the documentation: This module uses a rule-based rewriting engine (based on a regular-expression parser) to rewrite requested URLs on the fly.

So the url can look like example.com/2222 for the user, but then translated into example.com/?id=2222 on the server.

code-zoop
Note that this particular method assumes the Apache webserver is being used.
R. Bemrose
+2  A: 

Make sure mod_rewrite is enabled, and you'll need a few lines in an .htaccess file, similar to:

RewriteEngine on
RewriteBase /
RewriteRule (.*)$ index.php?id=$1 [L]

You can get more information (with lots of examples) here, or by searching for "htaccess pretty urls" in a search engine.

jnunn
Note that this particular method assumes the Apache webserver is being used.
R. Bemrose
+2  A: 

If you are unable to use mod_rewrite (which is the best way), you could use a 404 trap.

That is, normally example.com/2222 would show a 404 page to the user. Well if you set your server to point to a script of your choice instead of the default 404 page, you can now take the URL example.com/2222 and redirect the user to wherever you want.

mgroves