【问题标题】:htaccess URL wrong redirectionhtaccess URL 重定向错误
【发布时间】:2012-03-04 17:57:45
【问题描述】:

我想重定向

  • /about
  • /about/
  • /about.html
  • /about.html/
  • /weare/
  • /weare
  • /weare.html
  • /weare.html/

所有这些页面都应该重定向到about.html,我想用 .htaccess 来做到这一点。

我在尝试

RewriteRule ^(about|weare).*/ about.html [R=Permanent]

这有点工作,但不是我想要的。它还重定向了一些其他页面。

我已经按照 ThinkingMonkey 的说法添加了

如果您想进行永久重定向:

    RewriteCond %{REQUEST_URI} !^/about\.html$ [NC]
    RewriteRule ^(about|weare)(\.html)?/?$ about.html [L,R=301]

这是有效的,但它正在无限循环。

【问题讨论】:

    标签: html .htaccess mod-rewrite redirect rewrite


    【解决方案1】:

    这样做:

    RewriteRule ^(about|weare)(/|\.html/?)?$ about.html [L]
    

    如果您想进行永久重定向:

    RewriteCond %{REQUEST_URI} !^/about\.html$ [NC]
    RewriteRule ^(about|weare)(\.html)?/?$ about.html [L,R=301]
    

    【讨论】:

    • 第二个不工作。它正在无限循环..我认为它也在重定向.html
    • @Midars 这太尴尬了!太多的景点。检查更新。
    • @Midars 我刚刚在这里测试过。我没有得到任何重定向循环。你在同一个文件中还有其他重写规则吗?我刚刚优化了最后一行。
    • 我有但与这种情况无关...我会检查这个...无论如何谢谢..
    【解决方案2】:

    RewriteRule ^((about|weare)(.|/)?(html)?) about.html [NC]

    【讨论】:

    • 这是给 500 内部服务器错误
    • 对不起,你是对的。我编辑了它。顺便说一句:用于测试有两个很棒的工具:regexpalrewriteRule Tester
    • 谢谢,但这个 [NC] 不起作用,我希望它如何工作。如果我添加 [L,R=301] 它将进入无限循环
    猜你喜欢
    • 1970-01-01
    • 2013-11-26
    • 2013-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-18
    • 1970-01-01
    相关资源
    最近更新 更多