开发者

how to change the way of GET variables work in php

I dont like something like this: example.com/?id=22开发者_开发问答22. How to change it into example.com/2222?


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜