【问题标题】:Disallow index if typed by user如果用户键入则禁止索引
【发布时间】:2012-08-22 09:35:12
【问题描述】:

如果链接是http://example.com,默认情况下会重定向到http://example.com/index.html
(或.php 或类似的东西)。

但是如果用户在 url 中输入http://example.com/index.html,我想显示 404 错误。

我知道我能做到

重写引擎开启 RewriteRule index.html 404.html [R=304,L]

但我想要更通用的东西,它可以适用于每个页面。

【问题讨论】:

    标签: .htaccess


    【解决方案1】:

    或者简单地说:

    RewriteEngine On
    RewriteRule index\.(php|html?)$ 404.html [R=404,L]
    

    【讨论】:

    • 谢谢!!!正是我想要的!但我还有一个问题。为什么html后面还有?
    【解决方案2】:

    试试:

    RewriteEngine On
    RewriteCond %{THE_REQUEST} (index.(html|php)|/foo/bar)
    RewriteRule ^ 404.html [R=404,L]
    

    【讨论】:

    • 它适用于http://example.com/foo/bar 吗?它如何适用于每个索引(html 和 php 等)?
    猜你喜欢
    • 2013-04-24
    • 1970-01-01
    • 2021-09-15
    • 1970-01-01
    • 2015-03-22
    • 1970-01-01
    • 2017-12-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多