.htaccess - Reference capture groups of multiple RewriteCond in RewriteRule -


when have multiple rewritecond chained together, capture groups of last rewritecond can referenced %0-%9.

in following problem parameters in query string of url can in order. parse them fancy url need match each parameter in query string individually:

rewritecond %{query_string} param1=([^&]+) rewritecond %{query_string} param2=([^&]+) rewritecond %{query_string} param3=([^&]+) rewriterule ^foo$ bar/%1/%2/%3/ [r] 

like pointed out... doesn't work. fix this, reference capture group of previous rewritecond in next rewritecond , 'propagate' each parameter actual rewriterule:

rewritecond %{query_string} param1=([^&]+) rewritecond %1&%{query_string} ^([^&]*)&.*param2=([^&]+) rewritecond %1&%2&%{query_string} ^([^&]*)&([^&]*)&.*param3=([^&]+) rewriterule ^foo$ bar/%1/%2/%3/ [r] 

this should work, each additional parameter get's messier. other solution possibly parsing 1 parameter , redirecting client after each parameter (resulting in lengthy chain of redirects, avoid).

is there cleaner way of accessing capture groups of rewritecond's in rewriterule (e.g. possible name them or assign them variable can reference them somewhere else?)

you try constructing target url inside rewrite conditions:

rewritecond ##%{query_string}      (.*)##(|.*&)param1=([^&]+) rewritecond %1/%3##%{query_string} (.*)##(|.*&)param2=([^&]+) rewritecond %1/%3##%{query_string} (.*)##(|.*&)param3=([^&]+) rewritecond %1/%3##%{query_string} (.*)##(|.*&)param4=([^&]+) rewritecond %1/%3##%{query_string} (.*)##(|.*&)param5=([^&]+) rewritecond %1/%3##%{query_string} (.*)##(|.*&)param6=([^&]+)  rewriterule ^foo$ /bar%1/%3? [l,r] 

when try request:

/foo?param1=a&param2=b&param6=3&param3=4&param5=5&param4=6

i redirected to:

/bar/a/b/4/6/5/3

adding additional required query string parameters won't make more messy is.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -