开发者

How do we program such PHP scripts?

Sometimes we see websites that contain URLs like these:

somesite.com/123.php

somesite.com/124.php

somesite.com/125.php

the numbers before '.php' are the IDs of Mysql Query

somesite.com/123.php = somesite.com/file.php?id=123.

I noticed that these fi开发者_开发百科le [123.php,124.php,125.php] are not really stored in the server.

How can we do it ?


...using rewriting rules for apache, which normally are placed in .htaccess files.


In your specific example, you'd use a rewrite rule in the .htaccess file like so:

RewriteRule ^/somesite\.com/([0-9]+)\.php/$ file.php?id=$1 


.htaccess files with rewrite rules using mod_rewrite.

A couple of links to get you started:

A deeper look at mod_rewrite for Apache

URL Rewriting Guide

A beginner's guide to URL Rewriting

Good luck!


You have to employ some http redirects with an .htaccess file (on linux)


What you want is the mod_rewrite module in Apache (or the IIS equivalent if that's the case) and the .htaccess file.

The documentation is here if you're curious: http://httpd.apache.org/docs/2.0/misc/rewriteguide.html

And here's a sample rule for you that should do what you want (will redirect anything.php to index.php?id=anything):

RewriteRule ^(.*)\.php$ index.php?id=$1 [QSA,L]
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜