httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Björn Heller" <hel...@elitehost.biz>
Subject Re: [users@httpd] RedirectMatch wrongly matching single chars of a string?
Date Tue, 31 Jan 2006 02:07:22 GMT
Joshua Slive writes: 

> On 1/30/06, Björn Heller <heller@elitehost.biz> wrote:
>> Joshua Slive writes: 
>>
>> > On 1/30/06, Björn Heller <heller@elitehost.biz> wrote:
>> >
>> >> I want to redirect all requests like
>> >> site.com/something,
>> >> site.com/something/someotherthing,
>> >> site.com/something/xyz/someotherthing
>> >>
>> >> to site.com/something.html, no matter if or without trailing slash BUT NOT
>> >> if the URL is a .gif, .jpg etc.
>> >>
>> >> So I've got the following RedirectMatch:
>> >>
>> >> RedirectMatch permanent ^/(.[^/(\.gif)(\.jpg)]*)/?
>> >> http://www.site.com/$1.html
>> >
>> > You need to look again at a regex tutorial.  Stuff inside [] is a
>> > character class, not an arbitrary regex.  That means it will match any
>> > one of the set of characters included in the class.  You need
>> > something more like
>> > RedirectMatch permanent ^/(.*(?!\.(gif|jpg)))/?$ http://www.example.com/$1.html
>> > I haven't tested that, and the negative-lookahead assertion will
>> > certainly only work in httpd 2.x.
>> >
>> > Another way to do this that doesn't require as much regex magic is
>> > RewriteEngine On
>> > RewriteCond %{REQUEST_URI} !(gif|jpg)$
>> > RewriteRule ^/(.*)/?$ http://www.example.com/$1[R=permanent]
>> >
>> > Joshua. 
>>
>> Thanks for the reply. Yes, I was wrong with thinking [^gif] would match only
>> the whole string. Got that in the meantime. I just tested your proposal but
>> it does not work =/ It redirects to /file.gif.html, /file.gif.html.html etc.
>> etc. in an infinite loop. ergo: it matches and redirects.
> 
> You tried which proposal?  The RewriteRule one can be easily fixed by adding
> RewriteCond %{REQUEST_URI} !\.html$ 
> 
> Joshua.

I tried your RewriteMatch proposal. It could work with a RewriteCond and a 
RewriteRule but this wouldnt change the URL in the user's address bar and 
that's what I want.

---------------------------------------------------------------------
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


Mime
View raw message