【问题标题】:Rewrite index.php and index.html in .htaccess在 .htaccess 中重写 index.php 和 index.html
【发布时间】:2011-01-10 11:17:23
【问题描述】:

使用.htaccess,如何重写URL,这样当访问者键入时:

http://www.domain.com/index.php
http://www.domain.com/index.html

他们将被重定向到http://www.domain.com/

我尝试过重定向,但它让我陷入了循环......

如果你能帮我解决这个问题,请。

【问题讨论】:

    标签: .htaccess redirect mod-rewrite url-rewriting


    【解决方案1】:
    RewriteEngine On
    RewriteRule ^index\.(php|html?)$ http://www.mydomain.com/ [R=301,L]
    

    【讨论】:

    • 如果标志是 [NC,R,L] 而不是 [R=301,L] 会有什么区别?
    • @JosiahSprague 由于 NC,它也会匹配 InDeX.pHp,并使用状态码 302 而不是所需的 301 进行重定向。
    猜你喜欢
    • 2013-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-19
    • 1970-01-01
    • 2021-04-19
    • 1970-01-01
    相关资源
    最近更新 更多