Re: [users@httpd] Redirecting /foo//bar to /foo/bar without creating a loop

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Krist van Besien <krist.vanbesien@xxxxxxxxx> wrote:

> On 2/12/06, Fabian Keil <freebsd-listen@xxxxxxxxxxxxx> wrote:
> > I would like to redirect /foo//bar (and /foo///bar etc.)
> > to /foo/bar. So far I failed and I'm not sure if I did something
> > wrong or if it's impossible with the Redirect directive.
> >
> > At the moment my Apache server answers /foo//bar with 200 and sends
> > the document /foo/bar without letting the user know that the url was
> > wrong. If there is an easy way to disable this "feature" I'd like
> > to hear about it as well.
> 
> That multiple slashes are treated as one is a feature of the
> underlying filesystem. Apache gets a requests for /foo//bar, applies
> the necessary translations to it, and asks the underlying OS for
> <webroot>/foo//bar. It gets a document back, so all is OK from
> Apache's viewpoint.

Makes sense, is there an easy way to disable it anyway?
For example on apache.org you get a file not found if
you use more than one slash in a row. I could live with that.

> If you want double slashes in URLs to generate a redirect you are
> probably better of using a Rewrite
> 
> For example:
> 
> RewriteRule     (^.*)/{2,}(.*$)         $1/$2 [R,L]
> 
> (disclaimer: This is of the top of my head, didn't actually test
> this...)

Thanks for the suggestion.

* seems to be greedy on my apache version, therefore foo////bar
will be rewritten to foo///bar only.

Using *? results in a server error and I have no better idea how
to make * ungreedy.

Now I use:

RewriteRule ^([^/]*)/{2,}(.*$) http://www.fabiankeil.de/$1/$2 [R=Permanent,L]

It only works for multiple slashes after the first directory level,
but ATM that's good enough.

Fabian
-- 
http://www.fabiankeil.de/

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux