【问题标题】:Redirect example.com/index to exmple.com将 example.com/index 重定向到 exmple.com
【发布时间】:2014-02-13 03:42:31
【问题描述】:

由于一篇文章中的错误,我们的一个链接被添加为example.com/index 而不是example.com/index.html 或简单的example.com。我们目前无法访问该文章,也无法更改链接。

我正在考虑添加一个.htaccess 规则并将http://example.com/index 重定向到http://example.com。我找到了重定向子目录和文件的解决方案,但找不到仅适用于http://example.com/index(而不是完整的子目录)的简单解决方案,其他一些解决方案也失败了。

【问题讨论】:

    标签: .htaccess url mod-rewrite redirect


    【解决方案1】:

    如果请求/index 是错误的,它应该会导致找不到页面。因此,请在您的 .htaccess 文件中查看它是如何为您工作的。

    RewriteEngine On
    RewriteCond %{REQUEST_URI} ^/index$
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)$ / [R=301,L]
    

    【讨论】:

    • 工作,完美。谢谢!
    猜你喜欢
    • 2018-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-13
    • 2011-02-28
    • 2014-10-17
    • 2020-06-20
    相关资源
    最近更新 更多