RewriteCond referencia inversa variable de% 2

this is htaccess file on the server

RewriteEngine On

RewriteBase /

RewriteCond %{HTTP_HOST} !^www.
RewriteCond %{HTTP_HOST} ^([a-z0-9]+)\.domain.com(.*)$
RewriteRule ^(.*)$ http://domain.com/test\.php?user=%1&path=%2 [R]

According to my understanding of the above code if i request asher.domain.com/user it should rewrite to http://domain.com/test.php?user=asher&path=/user ¿derecho?

Instead i get http://domain.com/test.php?user=asher&path= El %2 is empty. but if i use $1 en lugar de %2 i seem to get the right result.

I might be doing the silliest mistake ever but I am not sure where I my mistake is. Help me out here guys? where is the mistake in the rewrite rules that %2 is not working for me?

preguntado el 09 de marzo de 12 a las 16:03

1 Respuestas

Usando el patrón de velas del $ syntax gives you RewriteRule backreferences, while the % Te regalaré RewriteCond backreferences. The mod_rewrite documentation covers this.

En tu caso, tu RewriteRule debería verse así:

RewriteRule ^(.*)$ http://domain.com/test\.php?user=%1&path=$1 [R]

Because you want the first group match from the previous RewriteCond and the first group match from the current RewriteRule.

respondido 09 mar '12, 16:03

oh. i was expecting '(.*)' in the second 'RewriteCond' would match to %2. is this not the case here? - santosh

lo hace, pero ${HTTP_HOST} won't have anything in it passed the .com. It's just the hostname, it doesn't contain the request URI. - Sean brillante

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.