You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Lazy <la...@gmail.com> on 2012/08/17 12:01:14 UTC

[users@httpd] RewriteCond backreference in virtualhost context

Hi All,

a simple mod_rewrite rules

RewriteEngine On

RewriteCond /home/docroot/test/$1 -f
RewriteRule ^(.+).test$ /test/$1 [L]

http://httpd.apache.org/docs/2.4/mod/mod_rewrite.html#rewritecond

in apache 2.2.x this works in vhost and .htaccess context, in apache
2.4.2 in vhost context $1 in RewriteCond is always empty

Is this a bug or I'm missing something ?

Regards,

Michal Grzedzicki

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] RewriteCond backreference in virtualhost context

Posted by Lazy <la...@gmail.com>.
2012/8/17 Eric Covener <co...@gmail.com>:
> On Fri, Aug 17, 2012 at 6:01 AM, Lazy <la...@gmail.com> wrote:
>> Hi All,
>>
>> a simple mod_rewrite rules
>>
>> RewriteEngine On
>>
>> RewriteCond /home/docroot/test/$1 -f
>> RewriteRule ^(.+).test$ /test/$1 [L]
>>
>> http://httpd.apache.org/docs/2.4/mod/mod_rewrite.html#rewritecond
>>
>> in apache 2.2.x this works in vhost and .htaccess context, in apache
>> 2.4.2 in vhost context $1 in RewriteCond is always empty
>>
>> Is this a bug or I'm missing something ?
>>
>
> Can you set LogLevel info rewrite:trace8 (2.4's  RewriteLog) and throw
> it into a pastebin?  There should not be a difference between the
> releases here.
>
> (re: other comments ITT, despite counter-intuitiveness RewriteRule's
> regex is evaluated first and captures are available in the preceding
> RewriteCond's)

I have just noticed that my config lacks '$', it was generated by
puppet and I didn't escape '$' properly.

After fixing this everything works as expected.

Thank You for your time.

Regards,
Michal Grzedzicki

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] RewriteCond backreference in virtualhost context

Posted by Eric Covener <co...@gmail.com>.
On Fri, Aug 17, 2012 at 6:01 AM, Lazy <la...@gmail.com> wrote:
> Hi All,
>
> a simple mod_rewrite rules
>
> RewriteEngine On
>
> RewriteCond /home/docroot/test/$1 -f
> RewriteRule ^(.+).test$ /test/$1 [L]
>
> http://httpd.apache.org/docs/2.4/mod/mod_rewrite.html#rewritecond
>
> in apache 2.2.x this works in vhost and .htaccess context, in apache
> 2.4.2 in vhost context $1 in RewriteCond is always empty
>
> Is this a bug or I'm missing something ?
>

Can you set LogLevel info rewrite:trace8 (2.4's  RewriteLog) and throw
it into a pastebin?  There should not be a difference between the
releases here.

(re: other comments ITT, despite counter-intuitiveness RewriteRule's
regex is evaluated first and captures are available in the preceding
RewriteCond's)

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] RewriteCond backreference in virtualhost context

Posted by Igor Cicimov <ic...@gmail.com>.
It is oposite as far as i know. You use the variables of a patern match
from RewrieCond in RewriteRule. Hence the order of the statements,
RewriteRule always comes after ReweiteCond and never the other way around.
But if you say so ...
 On Aug 17, 2012 8:41 PM, "Lazy" <la...@gmail.com> wrote:

> 2012/8/17 Igor Cicimov <ic...@gmail.com>:
> > Im really surprised your RewriteCond worked at all in any Apache version
> as
> > it doesn't make sense to me. The $1 at the end has a meaning of variable
> > which in your case has a value of ... what? Maybe if you tell us whar r
> you
> > trying to do someone can help you.
> >
> > On Aug 17, 2012 8:01 PM, "Lazy" <la...@gmail.com> wrote:
> >>
> >> Hi All,
> >>
> >> a simple mod_rewrite rules
> >>
> >> RewriteEngine On
> >>
> >> RewriteCond /home/docroot/test/$1 -f
> >> RewriteRule ^(.+).test$ /test/$1 [L]
> >>
> >> http://httpd.apache.org/docs/2.4/mod/mod_rewrite.html#rewritecond
> >>
> >> in apache 2.2.x this works in vhost and .htaccess context, in apache
> >> 2.4.2 in vhost context $1 in RewriteCond is always empty
> >>
> >> Is this a bug or I'm missing something ?
> >>
>
> please read the docs,
> "
> RewriteRule backreferences: These are backreferences of the form $N (0
> <= N <= 9). $1 to $9 provide access to the grouped parts (in
> parentheses) of the pattern, from the RewriteRule which is subject to
> the current set of RewriteCond conditions. $0 provides access to the
> whole string matched by that pattern.
> "
> this rule redirects xxx.test to /test/xxx if /test/xxx is present
>
> This can be used as an simple static cache.
>
> Regards,
>
> Michal Grzedzicki
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>

Re: [users@httpd] RewriteCond backreference in virtualhost context

Posted by Marcin 'Rambo' Roguski <ra...@id.uw.edu.pl>.
> please read the docs,
> "
> RewriteRule backreferences: These are backreferences of the form $N (0
> <= N <= 9).

You should read the docs, too. The keyword for you is: scope. You
cannot backreference outside the actual rewrite rule, and the
RewriteCond (i.e. the TRIGGER) is bogus at best, because you'd be
trying to backreference to... yes, what exactly?

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] RewriteCond backreference in virtualhost context

Posted by Lazy <la...@gmail.com>.
2012/8/17 Igor Cicimov <ic...@gmail.com>:
> Im really surprised your RewriteCond worked at all in any Apache version as
> it doesn't make sense to me. The $1 at the end has a meaning of variable
> which in your case has a value of ... what? Maybe if you tell us whar r you
> trying to do someone can help you.
>
> On Aug 17, 2012 8:01 PM, "Lazy" <la...@gmail.com> wrote:
>>
>> Hi All,
>>
>> a simple mod_rewrite rules
>>
>> RewriteEngine On
>>
>> RewriteCond /home/docroot/test/$1 -f
>> RewriteRule ^(.+).test$ /test/$1 [L]
>>
>> http://httpd.apache.org/docs/2.4/mod/mod_rewrite.html#rewritecond
>>
>> in apache 2.2.x this works in vhost and .htaccess context, in apache
>> 2.4.2 in vhost context $1 in RewriteCond is always empty
>>
>> Is this a bug or I'm missing something ?
>>

please read the docs,
"
RewriteRule backreferences: These are backreferences of the form $N (0
<= N <= 9). $1 to $9 provide access to the grouped parts (in
parentheses) of the pattern, from the RewriteRule which is subject to
the current set of RewriteCond conditions. $0 provides access to the
whole string matched by that pattern.
"
this rule redirects xxx.test to /test/xxx if /test/xxx is present

This can be used as an simple static cache.

Regards,

Michal Grzedzicki

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] RewriteCond backreference in virtualhost context

Posted by Igor Cicimov <ic...@gmail.com>.
Im really surprised your RewriteCond worked at all in any Apache version as
it doesn't make sense to me. The $1 at the end has a meaning of variable
which in your case has a value of ... what? Maybe if you tell us whar r you
trying to do someone can help you.
 On Aug 17, 2012 8:01 PM, "Lazy" <la...@gmail.com> wrote:

> Hi All,
>
> a simple mod_rewrite rules
>
> RewriteEngine On
>
> RewriteCond /home/docroot/test/$1 -f
> RewriteRule ^(.+).test$ /test/$1 [L]
>
> http://httpd.apache.org/docs/2.4/mod/mod_rewrite.html#rewritecond
>
> in apache 2.2.x this works in vhost and .htaccess context, in apache
> 2.4.2 in vhost context $1 in RewriteCond is always empty
>
> Is this a bug or I'm missing something ?
>
> Regards,
>
> Michal Grzedzicki
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>