mod rewrite - How to get back-reference variables in multiple RewriteCond with .htaccess -


these rewrite rules don't seem work. not possible or missing something

the problematic rule second one, notice back-reference %1

rewritecond %{request_uri} ^/([a-za-z\.]+)/.*$ [nc] rewritecond %{http_cookie} route_controller_%1=([^;]+) [nc] rewriterule ^(.*)$ http://example2.com/%1/_/$1 [l] 

this expecting happen. given url

http://example.com/abc/home 

the first rule should store abc in %1 want second rule cookie called route_controller_abc , if found third rule rewite to

http://example2.com/thevalueofthecookie/_/home 

but seconf rule doesn't seem using %1 back-reference.

any ideas?

the reason string substitution occurs in first parameter on cond , not on rexexp. have hack simulate parameters in regexps using \1 etc.

you can pick directory in rule regexp, since execution order rule regexp, cond1, cond2,... rule substitution. eg. ^(*.?)/.*$ abc/homewill set $1 abc , $0 abc/home. hence try like:

rewritecond $1:%{http_cookie} ^(.*?):.*\broute_controller_\1=([^;]+) [nc] rewriterule ^(*.?)/.*$        http://example2.com/%2/_/$0            [l] 

note controller in %2 %1 used bind directory in cond regexp.

hope helps , answers direct q. hovever, little twitchy using unvalidated cookies redirection. if doing either tighten validation of parameter ([^;]+) or move small php redirector script , validation there :-)


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -