You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Gary Wilson <gw...@plus.net> on 2005/03/22 11:53:29 UTC

[users@httpd] Regexps in rewrite rules

I understand that Apache 2.0 uses Perl style regexps.  With this in
mind, I wrote the following rewrite rule to force a mime type of a 
CGI application for antyhing under /cgi-bin EXCEPT files inding in 
.html - however the rule always returns "Not matched" in the rewrite 
logs, and no matter how I attempt this rule, it never seems to match. 

Other rules I have written with more vanilla regular expressions all
work fine, but I can't seem to do the following negation successfully.

RewriteRule  /cgi-bin/.*(?!\.html
$) /local/apache/cgi-bin/cgiwrap/%{ENV:UID}/$1
[T=application/x-httpd-cgi,NS]

Can anyone advise what is wrong with this rule please?

Thanks

GW



---------------------------------------------------------------------
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] Regexps in rewrite rules

Posted by Brian V Hughes <br...@Dartmouth.EDU>.
On Mar 22, 2005, at 10:55 AM, Gary Wilson wrote:
> Still interested as to why my original solution won't work though
> (I tried with and without line terminator etc - in fact I've tried over
> 10 incarnations of that regexp - just can't seem to get perl style
> negations working under apache) - but that's for another time and
> place now :)

The simplest answer for why your original rule didn't work is you can't 
use back references with "not match" patterns. Remember that a "not 
match" is the same as accepting a failure to match. If you fail to 
match, then there won't be anything matched on that you can store in a 
back reference.

-Brian


---------------------------------------------------------------------
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] Regexps in rewrite rules

Posted by Gary Wilson <gw...@plus.net>.
On Tue, 2005-03-22 at 09:03 -0500, Joshua Slive wrote:

> Although I'm not a regex expert, I can see a number of things that
> could be wrong there, such as including the line termination character
> inside the () and the fact that the $1 will always be empty.  But why
> not just avoid the problem by using something like:
> 
> RewriteCond %{REQUEST_URI} !.*\.html$
> RewriteRule  /cgi-bin/(.*) /local/apache/cgi-bin/cgiwrap/%{ENV:UID}/$1
> [T=application/x-httpd-cgi,NS]


Joshua,

Thanks for that alternate solution, which works nicely with my other
rules and does what it says on the tin :)

Still interested as to why my original solution won't work though 
(I tried with and without line terminator etc - in fact I've tried over 
10 incarnations of that regexp - just can't seem to get perl style
negations working under apache) - but that's for another time and 
place now :)

Thanks again

GW


---------------------------------------------------------------------
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] Regexps in rewrite rules

Posted by Joshua Slive <js...@gmail.com>.
On Tue, 22 Mar 2005 10:53:29 +0000, Gary Wilson <gw...@plus.net> wrote:
> 
> I understand that Apache 2.0 uses Perl style regexps.  With this in
> mind, I wrote the following rewrite rule to force a mime type of a
> CGI application for antyhing under /cgi-bin EXCEPT files inding in
> .html - however the rule always returns "Not matched" in the rewrite
> logs, and no matter how I attempt this rule, it never seems to match.
> 
> Other rules I have written with more vanilla regular expressions all
> work fine, but I can't seem to do the following negation successfully.
> 
> RewriteRule  /cgi-bin/.*(?!\.html
> $) /local/apache/cgi-bin/cgiwrap/%{ENV:UID}/$1
> [T=application/x-httpd-cgi,NS]
> 
> Can anyone advise what is wrong with this rule please?

Although I'm not a regex expert, I can see a number of things that
could be wrong there, such as including the line termination character
inside the () and the fact that the $1 will always be empty.  But why
not just avoid the problem by using something like:

RewriteCond %{REQUEST_URI} !.*\.html$
RewriteRule  /cgi-bin/(.*) /local/apache/cgi-bin/cgiwrap/%{ENV:UID}/$1
[T=application/x-httpd-cgi,NS]

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