什么导致这个301redirect循环?

我在我的Ubuntu / etc / apache2 / sites-available文件中有几个Redirect指令:

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 

据我所知,他们都正常工作。

但是,当我使用web-sniffer.net访问http://example.com/feed/index.xml时,它会返回一个指向http://example.com/feed/index.xmlindex.xml的301,然后获取redirect到http://example.com/feed/index.xmlindex.xmlindex.xml等等。

看来,其中一个模式是匹配时,我不期望它。 如果我省略了最后两个redirect,则循环停止,但是当我应该时,我不会redirect/馈送和/馈送/。

任何想法如何使这个工作正确?

(我认为这个问题与这个问题有关: 无限redirect循环? )

Redirect是简单的前缀匹配,并且“超出匹配的URL-Path的附加path信息将被追加到目标URL”。

因此, /feed/ index.xml会将您的第三条规则/feed/与其他path信息index.xml相匹配,以便将其redirect到/feed/index.xml并附加index.xml

解决scheme是使用RedirectMatch并使用锚点:

 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