What's causing this 301 redirect loop?

5,162

Redirect is simple prefix matching and "[a]dditional path information beyond the matched URL-Path will be appended to the target URL."

Thus /feed/index.xml matches your third rule /feed/ with additional path information index.xml so it gets redirected to /feed/index.xml with index.xml appended to it.

The solution is to use RedirectMatch and use anchors:

RedirectMatch 301 ^/rss.xml$ http://example.com/feed/index.xml
RedirectMatch 301 ^/atom.xml$ http://example.com/feed/atom/index.xml
RedirectMatch 301 ^/feed/$ http://example.com/feed/index.xml
RedirectMatch 301 ^/feed$ http://example.com/feed/index.xml
Share:
5,162

Related videos on Youtube

pingswept
Author by

pingswept

Embedded systems engineer. I am currently working on an embedded Linux board for my new startup, Rascal Micro.

Updated on September 17, 2022

Comments

  • pingswept
    pingswept over 1 year

    I have several Redirect directives in my Ubuntu /etc/apache2/sites-available file:

        Redirect 301 /rss.xml http://example.com/feed/index.xml
        Redirect 301 /atom.xml http://example.com/feed/atom/index.xml
        Redirect 301 /feed/ http://example.com/feed/index.xml
        Redirect 301 /feed http://example.com/feed/index.xml
    

    They all work correctly, so far as I can tell.

    However, when I visit http://example.com/feed/index.xml with web-sniffer.net, it returns a 301 pointing at http://example.com/feed/index.xmlindex.xml, which then gets redirected to http://example.com/feed/index.xmlindex.xmlindex.xml, and so forth.

    It seems that one of the patterns is matching when I don't expect it to. If I omit the last two redirects, the looping is stopped, but then I'm not redirecting /feed and /feed/ when I should.

    Any ideas of how make this work correctly?

    (I think the problem is related to this question: Infinite redirect loop?)

  • pingswept
    pingswept over 13 years
    Thank you, sir or madam! That did the trick. I don't know why I found that so difficult-- it's clearly in the docs here: httpd.apache.org/docs/2.2/mod/mod_alias.html#redirectmatch