php mod rewrite

php mod rewrite

i have a rule which:

 RewriteRule ^cat_ap~([^~]+)~(.*)\.htm$ /urban/cat_ap.php?$1=$2 [L] 

goes to cat_ap.php?nid=xxxxxxx

now I have to add some other support.


needs to resolve to cat_ap.php?pnid=290&nid=96666 (I'm not concerned with the end of the link though I do need it in there for legacy paid search traffic).

Also, I need to get a page_num out of the link to calculate pagination.

 cat_ap~PageNum_GetProduct~10~nid~290.htm needs to resolve to cat_ap.php?PageNum_GetProduct=10&nid=290 

I kind of need to encompass all these scenarios either into a single or multiple rules.

Any ideas? I'm reading up on this right now but am stuck.


HTTP Caching, Browser Differences


Apache Server Timeout with an error message “The page cannot be displayed” for a PHP script
In this kind of scenario i'd suggest to use the rule RewriteRule ^cat_ap(~.*).htm$ /urban/cat_ap.php?$1 [L] in order to catch all possible combination and decompose the string inside your php application..
500 error when trying to add expires header to .htaccess
In this way it will be easier to debug parameters, since apache can be pretty bastard sometimes..
What to expect and prepare for when moving from LAMP to SAMP

disabling Zend Framework

Best way to stop Firefox pipe-lining from messing up my stats


.htaccess and sessions for security?
Here's a solution which will loop over key/value pairs in your URL:.
Django dynamic content in VPS environment - when do I need a queue?
RewriteRule ^cat_ap~([^~]+)~([^~]+)(.*)\.htm$ cat_ap$1?$1=$2 [N,QSA] RewriteRule ^cat_ap(.*)\.htm$ /urban/cat_ap.php [L] 
It grabs the first pair off the URL, then rewrites it to the exact same URL without that pair, adds the pair to the query string ([QSA]) and starts the rewriting process over again ([N]).

When there are no more key/value pairs in the URL, it rewrites it to your script's location and terminates rewriting ([L])..
cat_ap~pnid~290~nid~96666~posters~Sports.htm => /urban/cat_ap.php?posters=Sports&nid=96666&pnid=290 cat_ap~PageNum_GetProduct~10~nid~290.htm => /urban/cat_ap.php?nid=290&PageNum_GetProduct=10 
(Note that the order of parameters is reversed; this will only matter if the same parameter appears more than once.).


Try this for both cases:.
RewriteRule ^cat_ap~([^~]+)~([0-9]+)~([^~]+)~([0-9]+)(.*)\.htm$ /urban/cat_ap.php?$1=$2&$3=$4 [L] 

88 out of 100 based on 58 user ratings 658 reviews