开发者

url masking mod_rewrite

开发者 https://www.devze.com 2023-02-10 23:12 出处:网络
I am slowly but surely learning php, and all is going well up until now. I am looking to do a url rewrite, my DB is relatively indepth and a typical url would look like:

I am slowly but surely learning php, and all is going well up until now.

I am looking to do a url rewrite, my DB is relatively indepth and a typical url would look like:

players.php?position=1&teamid=4&playerid=129

basically i want to return /Defender/Arsenal/Thomas-Vermaelen/ which are basically the names associated with the ID's in the database. This one page generates lots of different pages and I wanted to workout how to use 开发者_JS百科the name in the URL instead of the ID number.

Im 99% sure this can be done as I have been looking in detail at the Joomla CMS system, and wondered if anyone could help shed some light on this please?

Thanks in advance

Richard :)


I think the easiest would be to simply map the requested URI /Defender/Arsenal/Thomas-Vermaelen/ onto /players.php?position=Defender&teamid=Arsenal&playerid=Thomas-Vermaelen:

RewriteRule ^/([A-Za-z]+)/([\w-]+)/([\w-]+)/$ /players.php?position=$1&teamid=$2&playerid=$3

Then in you PHP script you can check whether the parameter value was numeric or alphabetic and fetch the the numeric ID in case of the latter.

0

精彩评论

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