You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Brad Bowman <br...@atendesigngroup.com> on 2006/06/26 23:30:39 UTC

[users@httpd] mod_rewrite combined with scriptalias

I seem to be having trouble making url rewrite if it's inside a  
ScriptAlias'd directory.

I have the following line in my httpd.conf file:
ScriptAlias  /cgi-bin/ /var/www/vhosts/site/cgi-bin/

And the following two rules in .htaccess:
RewriteRule ^random/miva(.*)$ /mm5/merchant.mvc$1 [R=301]
RewriteRule ^cgi-bin/miva(.*)$ /mm5/merchant.mvc$1 [R=301]

The first rule properly rewrites when browsing to site/random/miva? 
directives=here&more=here, while the second rule refuses to rewrite.  
I've had a terrible time finding much reliable information on the  
issue, I've found one website that  claims mod_rewrite will not work  
on a directory that is a scriptalias, because scriptalias is a  
'deeper' apache module, and therefor takes precedence  before  
mod_rewrite will kick in. My personal experience on this leads me to  
believe this could be true, but since I was only able to find the  
information on one site, with nothing to back it up, I figured i'd  
see what you guys had to say about that.

Thanks in advance for your time.
-Brad Bowman


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Mod-rewrite not finding text that is found by regex test site.

Posted by Michael Daly <mi...@magma.ca>.
On 28 Jun 2006 at 15:35, Joshua Slive wrote:

> Then it is unlikely this is a PCRE issue.  I really don't know what
> the problem here is, although I'd suggest posting the whole RewriteLog with
> loglevel 9 for a request, just for interest sake.

I got it figured out.  It looks like mod_rewrite is very picky about the 
use of the caret (^) and dollar ($) at the beginning and end of strings.  
I removed them and it now works regardless of what rewrite precedes the 
problem statement:

RewriteCond  $1    /cgi-sys/cgiwrap/guille/wiki.pl/([A-Z])(.*)
RewriteRule ^(.*)$ /cgi-sys/cgiwrap/guille/wiki.pl/${lc:%1}%2        [NS]

RewriteCond  $1    /cgi-sys/cgiwrap/guille/wiki.pl/(.*)([a-z])([A-Z])(.*) 
RewriteRule ^(.*)$ /cgi-sys/cgiwrap/guille/wiki.pl/%1%2_${lc:%3}%4 [N,NS]


Thanks for your help - even though you didn't pin down the problem, I was 
able to start testing new things based on your hints.  I'd still be lost 
otherwise.

Mike


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Mod-rewrite not finding text that is found by regex test site.

Posted by Joshua Slive <jo...@slive.ca>.
On 6/28/06, Michael Daly <mi...@magma.ca> wrote:
> On 28 Jun 2006 at 10:39, Joshua Slive wrote:
>
> > Can you verify if you get the same result if you put that regex on its own
> > in a RewriteRule (rather than in a big chain)?
>
> Interestingly, it works on its own, but not with the preceding rules.

Then it is unlikely this is a PCRE issue.  I really don't know what
the problem here is, although I'd suggest posting the whole RewriteLog
with loglevel 9 for a request, just for interest sake.

Joshua.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Mod-rewrite not finding text that is found by regex test site.

Posted by Michael Daly <mi...@magma.ca>.
On 28 Jun 2006 at 10:39, Joshua Slive wrote:

> Can you verify if you get the same result if you put that regex on its own
> in a RewriteRule (rather than in a big chain)?

Interestingly, it works on its own, but not with the preceding rules.

I tried just the immediately preceding rule and cond and it fails:

RewriteCond   $1   ^/cgi-sys/cgiwrap/guille/wiki.pl/([A-Z])(.*)       
RewriteRule ^(.*)$ ^/cgi-sys/cgiwrap/guille/wiki.pl/${lc:%1}%2    [NS]

RewriteCond   $1   ^/cgi-sys/cgiwrap/guille/wiki.pl/(.*)([a-z])([A-Z])(.*) 
RewriteRule ^(.*)$ ^/cgi-sys/cgiwrap/guille/wiki.pl/%1%2_${lc:%3}%4 [N,NS]


> There is some possibility that this is a PCRE issue (the regex engine
> used by apache) with greedy processing.  (It may not be backtracking
> to match the third group after it already matches the first and
> second.)  

That would be a problem.  I could see the first two matching fooBar as
%1 fooBa
%2 r

Is double bracing legal to force order?  E.g.:

(.*)(([a-z])([A-Z]))(.*)

I'll try that and see what happens.


> If so, you could probably work around it by using
> ...wiki.pl/([a-z]+)([A-Z])(.*)

Unfortunately, that is not general enough to work.  It would work on:

fooBar  (one iteration)

but fail on:

foo_barName  (e.g requires second iteration and underscore not matchable.)

Generalizing to ([a-z0-9_]+)([A-Z])(.*) would fail on:

from_Dave (not camel case in the first place and it would match)

Mike


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Mod-rewrite not finding text that is found by regex test site.

Posted by Joshua Slive <jo...@slive.ca>.
On 6/27/06, Michael Daly <mi...@magma.ca> wrote:
> On 27 Jun 2006 at 16:45, Joshua Slive wrote:
>
> > On 6/26/06, Michael Daly <mi...@magma.ca> wrote:
> > > I'm trying to catch camelCase names.  The mod_rewrite log file
> > > shows:
> > >
> > > RewriteCond: input='^/cgi-sys/cgiwrap/guille/wiki.pl/fooBar'
> > > pattern='^/cgi-sys/cgiwrap/guille/wiki.pl/(.*)([a-z])([A-Z])(.*)' =>
> > > not-matched
> > >
> > > Testing at www.regular-expressions.info/javascriptexample.html
> > > gives:
> > >   %1=/cgi-sys/cgiwrap/guille/wiki.pl/fo
> > >   %2=0
> > >   %3=B
> > >   %4=ar
> [...]
> > Can you show us the exact set of RewriteCond/RewriteRules you are
> > using?
>
> The following will:
> 1) define lc as a lower case function
> 2) check for desired URI and replace "$" with "/query string"
> 3) change first upper case letter to lower case (e.g. CamelCase to
> camelCase)
>
> Up to this point, the log file shows everything working as expected.
>
> 4) check for next camel case and change to lower case with preceding
> underscore - (e.g. camelCase to camel_case )
>
> This fails with log file output as shown in previous message.
>
>
> RewriteMap  lc  int:tolower
> RewriteCond %{REQUEST_URI} ^/cgi-sys/cgiwrap/guille/wiki.pl$     [NC]
> RewriteRule  .*  /cgi-sys/cgiwrap/guille/wiki.pl/%{QUERY_STRING} [NS]
> RewriteCond   $1   ^/cgi-sys/cgiwrap/guille/wiki.pl/([A-Z])(.*)
> RewriteRule ^(.*)$ ^/cgi-sys/cgiwrap/guille/wiki.pl/${lc:%1}%2   [NS]
> RewriteCond   $1   ^/cgi-sys/cgiwrap/guille/wiki.pl/(.*)([a-z])([A-Z])(.*)
> RewriteRule ^(.*)$ ^/cgi-sys/cgiwrap/guille/wiki.pl/%1%2_${lc:%3}%4 [N,NS]

Can you verify if you get the same result if you put that regex on its
own in a RewriteRule (rather than in a big chain)?

There is some possibility that this is a PCRE issue (the regex engine
used by apache) with greedy processing.  (It may not be backtracking
to match the third group after it already matches the first and
second.)  If so, you could probably work around it by using
...wiki.pl/([a-z]+)([A-Z])(.*)
in your regex (and obviously changing your substitution variables to
match).  And as a bonus, that regex should be substantially faster
since it doesn't require all the back-tracking to find a match.

Joshua.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Mod-rewrite not finding text that is found by regex test site.

Posted by Michael Daly <mi...@magma.ca>.
On 27 Jun 2006 at 16:45, Joshua Slive wrote:

> On 6/26/06, Michael Daly <mi...@magma.ca> wrote:
> > I'm trying to catch camelCase names.  The mod_rewrite log file
> > shows:
> >
> > RewriteCond: input='^/cgi-sys/cgiwrap/guille/wiki.pl/fooBar'
> > pattern='^/cgi-sys/cgiwrap/guille/wiki.pl/(.*)([a-z])([A-Z])(.*)' =>
> > not-matched
> >
> > Testing at www.regular-expressions.info/javascriptexample.html
> > gives:
> >   %1=/cgi-sys/cgiwrap/guille/wiki.pl/fo
> >   %2=0
> >   %3=B
> >   %4=ar
[...] 
> Can you show us the exact set of RewriteCond/RewriteRules you are
> using?

The following will:
1) define lc as a lower case function
2) check for desired URI and replace "$" with "/query string"
3) change first upper case letter to lower case (e.g. CamelCase to 
camelCase)

Up to this point, the log file shows everything working as expected.

4) check for next camel case and change to lower case with preceding 
underscore - (e.g. camelCase to camel_case )

This fails with log file output as shown in previous message.


RewriteMap  lc  int:tolower
RewriteCond %{REQUEST_URI} ^/cgi-sys/cgiwrap/guille/wiki.pl$     [NC]
RewriteRule  .*  /cgi-sys/cgiwrap/guille/wiki.pl/%{QUERY_STRING} [NS]
RewriteCond   $1   ^/cgi-sys/cgiwrap/guille/wiki.pl/([A-Z])(.*)       
RewriteRule ^(.*)$ ^/cgi-sys/cgiwrap/guille/wiki.pl/${lc:%1}%2   [NS]
RewriteCond   $1   ^/cgi-sys/cgiwrap/guille/wiki.pl/(.*)([a-z])([A-Z])(.*)
RewriteRule ^(.*)$ ^/cgi-sys/cgiwrap/guille/wiki.pl/%1%2_${lc:%3}%4 [N,NS]


Mike


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


[users@httpd] Apache reverse proxy server: How to add a charset for libxml2 and libiconv?

Posted by fr...@netscape.net.
Hi,
Any body know how to add a charset for libxml2? It is required for mod_proxy_html when setting up Apache reverse proxy server.
 
Thanks a lot!
 
Frank Peng.

Re: [users@httpd] Mod-rewrite not finding text that is found by regex test site.

Posted by Joshua Slive <jo...@slive.ca>.
On 6/26/06, Michael Daly <mi...@magma.ca> wrote:
> I'm trying to catch camelCase names.  The mod_rewrite log file shows:
>
> RewriteCond: input='^/cgi-sys/cgiwrap/guille/wiki.pl/fooBar'
> pattern='^/cgi-sys/cgiwrap/guille/wiki.pl/(.*)([a-z])([A-Z])(.*)'
> => not-matched
>
> Testing at www.regular-expressions.info/javascriptexample.html
> gives:
>   %1=/cgi-sys/cgiwrap/guille/wiki.pl/fo
>   %2=0
>   %3=B
>   %4=ar
> Which is what I would expect.
>
> Is this a bug?
>
> I'm using Apache 2.0.55.

Can you show us the exact set of RewriteCond/RewriteRules you are using?

Joshua.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


[users@httpd] Mod-rewrite not finding text that is found by regex test site.

Posted by Michael Daly <mi...@magma.ca>.
I'm trying to catch camelCase names.  The mod_rewrite log file shows:

RewriteCond: input='^/cgi-sys/cgiwrap/guille/wiki.pl/fooBar'
pattern='^/cgi-sys/cgiwrap/guille/wiki.pl/(.*)([a-z])([A-Z])(.*)' 
=> not-matched

Testing at www.regular-expressions.info/javascriptexample.html
gives:
  %1=/cgi-sys/cgiwrap/guille/wiki.pl/fo
  %2=0
  %3=B
  %4=ar
Which is what I would expect.

Is this a bug?

I'm using Apache 2.0.55.

Mike


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] mod_rewrite combined with scriptalias

Posted by Joshua Slive <jo...@slive.ca>.
On 6/26/06, Brad Bowman <br...@atendesigngroup.com> wrote:
> I seem to be having trouble making url rewrite if it's inside a
> ScriptAlias'd directory.
>
> I have the following line in my httpd.conf file:
> ScriptAlias  /cgi-bin/ /var/www/vhosts/site/cgi-bin/
>
> And the following two rules in .htaccess:
> RewriteRule ^random/miva(.*)$ /mm5/merchant.mvc$1 [R=301]
> RewriteRule ^cgi-bin/miva(.*)$ /mm5/merchant.mvc$1 [R=301]
>
> The first rule properly rewrites when browsing to site/random/miva?
> directives=here&more=here, while the second rule refuses to rewrite.
> I've had a terrible time finding much reliable information on the
> issue, I've found one website that  claims mod_rewrite will not work
> on a directory that is a scriptalias, because scriptalias is a
> 'deeper' apache module, and therefor takes precedence  before
> mod_rewrite will kick in. My personal experience on this leads me to
> believe this could be true, but since I was only able to find the
> information on one site, with nothing to back it up, I figured i'd
> see what you guys had to say about that.

Where is the .htaccess located?  In the DocumentRoot or in the cgi-bin
directory?

The easiest fix for this would be to put the RewriteRule's in the
httpd.conf instead of in .htaccess (with appropriate path
adjustments).

Joshua.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org