简体   繁体   中英

url masking mod_rewrite

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 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM