I have been searching for a solution to this for some time and have not found it on the web or these forums.
What I need to do is a tricky mod_rewrite that takes a dynamic length URL such as:
http://www.some-site.com/news_list/text_size~16/language~eng/organization~asc/May_News.html
...and then transforms it using mod_rewrite to the following:
http://www.some-site.com/news_list.php?text_size=16&language=eng&organization=asc
If the querystring was going to be fixed length, always having 3 parameters (text_size, language, organization) then an easy RewriteRule would solve the problem:
Code:
RewriteRule ^([a-z0-9_]+)~([a-z0-9_]+)\/([a-z0-9_]+)~([a-z0-9_]+)\/([a-z0-9_]+)~([a-z0-9_]+)\/([a-z0-9_]+)~([a-z0-9_]+)\/?[a-z0-9_]+\.html$ news_list.php?$1=$2&$3=$4&$5=$6 [NC]
However, what if the URL could contain any number of parameters to be rewritten? Instead of three, how about 30. This and the number of parameters may rarely be the same, only forming a typical pattern of "/var~val/var~val/".
With PHP the solution is simply to snip off the matched pattern, preg_replace() the original URL with the appropriate translations of "/" -> "&" and "~" to "=" and then put everything back together into the final URL.
How can this be done with mod_rewrite and still maintain the dynamic nature of a URL camouflaged to appear static??