1

I have an Apache server (version 2.4.62-1~deb12u2 from Debian 12 “Bookworm”, currently the stable version of Debian) serving a site http://www.example.tld/ with UserDir activated, so http://www.example.tld/~myname/ fetches stuff from /home/myname/public_html/ — so far so good.

Now for some reason, either a typo or a mishandled relative link or something, links with multiple slashes, of the form http://www.example.tld/~myname//somestuff have started to exist on the Web. Google doesn't like this because it thinks they're duplicates. So I would like to redirect any such URL to the canonical http://www.example.tld/~myname/somestuff. I'm using RedirectMatch because I'd like to avoid the complexity of mod_rewrite. So naturally, I tried this:

RedirectMatch permanent ^/~myname//+(.*)$ /~myname/$1

but it has no effect (no matter if I place it before or after the directive enabling UserDir): it's as if the directive weren't there. Thinking maybe I was editing the wrong file or using the wrong regexp syntax or something, I checked:

RedirectMatch permanent ^/test//+(.*)$ /~myname/$1     # Works fine!

and this does, indeed, redirect http://www.example.tld/test//somestuff to http://www.example.tld/~myname/somestuff removing the double slash in passing (whereas http://www.example.tld/test/somestuff isn't matched at all and returns 404, as expected) — so there's no doubt that the file is read and my redirections work in general. Then I thought maybe you can't redirect on userdirs at all, but!

RedirectMatch permanent ^/~test/+(.*)$ /~myname/$1     # Works fine!

This one works fine, and it does remove multiple slashes as it's supposed to: http://www.example.tld/~test//somestuff goes to http://www.example.tld/~myname/somestuff as desired. And it's not a problem of ~myname existing either, because:

RedirectMatch permanent ^/~test//+(.*)$ /~myname/$1    # No effect!

seems to be completely ignored (http://www.example.tld/~test//somestuff returns 404 rather than redirecting as it did in the previous test).

At this point I think I'm going crazy. Note that I also tried redirecting from inside the .htaccess file in /home/myname/ without any more success.

Now before I call this an Apache bug, what I'd like to ask is:

  • Is there something obviously wrong with what I'm trying to do? Is this behavior documented?

  • Can someone else reproduce the above strange effect? My Apache config is a bit complicated (e.g., I'm also using mod_jk — not in the same place, but you'd never know what strange interactions there may be) and I can't easily create a minimal working example. It's also complicated for me to try different Apache versions, so if someone can confirm the strangeness on later versions, or tell me it's gone, I'd appreciate it.

  • Did I miss another way I could work around this, and still get http://www.example.tld/~myname/somestuff to redirect to http://www.example.tld/~myname/somestuff in a different way? Does mod_rewrite have the same issue?

  • Should I bug-report this? What other tests might I do beforehand?

0

You must log in to answer this question.

Browse other questions tagged .