【问题标题】:A simple htaccess redirect一个简单的 htaccess 重定向
【发布时间】:2009-07-28 04:48:27
【问题描述】:

如何编写一个重定向规则,让我同时使用http://www.site.com/rsshttp://www.site.com/anydirectory/rss 而不是http://www.site.com/rss.xmlhttp://www.site.com/anydirectory/rss.xml

我想我很接近了,但由于某种原因,今天是星期一。

RewriteRule ^(.*)/rss.\xml/$ $1/rss [L]

【问题讨论】:

  • @Sean 和@Patrick 是否在正确的轨道上?是否希望 site.com/rss 重定向到 site.com/rss.xml?
  • 是的,他们明白了。感谢您的帮助。

标签: .htaccess redirect


【解决方案1】:

我认为这就是你想要的(你把它们颠倒了):

RewriteRule ^(.+/)?rss$ $1rss.xml [L]

【讨论】:

    【解决方案2】:

    这是一个猜测,但看起来您打算转义 . 并使用 \. 而不是 .\ 完成

    RewriteRule ^(.*)/rss\.xml$ $1/rss [L]
    

    【讨论】:

    • 很好地了解丹尼斯,谢谢。我试图逃避它,但我一定是打错了。它更接近了,但它仍然无法正常工作。
    【解决方案3】:

    听起来你有 XML 文件,并且你想让没有 XML 扩展名的 URI 工作。

    # translate /rss to /rss.xml
    RewriteRule ^rss$ /rss.xml 
    
    # translate /anydirectory/rss to /anydirectory/rss.xml
    RewriteRule ^(.+)/rss$ /$1/rss.xml 
    

    您尝试的代码表明相反。

    # translate /rss.xml to /rss
    RewriteRule ^rss\.xml$ /rss 
    
    # translate /anydirectory/rss to /anydirectory/rss.xml
    RewriteRule ^(.+)/rss\.xml$ /$1/rss 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-03
      • 1970-01-01
      • 2016-01-28
      • 2011-07-14
      相关资源
      最近更新 更多