【问题标题】:prevent direct URL access to php and html pages via .htaccess防止通过 .htaccess 直接 URL 访问 php 和 html 页面
【发布时间】:2016-11-22 13:54:12
【问题描述】:

我知道可以通过 .htaccess 规则阻止直接 URL 访问,但我对元字符或转义知之甚少。

这些是我的 xammp/htdocs 文件夹中的文件,使用 本地主机:

index.php
createScheme.php
several someother.php

我希望仅为 index.php 和 createScheme.php 启用直接访问,并且应阻止所有其他页面直接访问。

请帮忙!

【问题讨论】:

标签: php apache .htaccess url


【解决方案1】:

这个.htaccess 文件将只允许用户打开index.php。尝试访问任何其他文件将导致 403 错误。

Order deny,allow
Deny from all

<Files "index.php">
    Allow from all
</Files>

如果您还想对某些文件使用身份验证,您只需在我的示例末尾添加当前文件中的内容即可。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-05-27
    • 2010-11-05
    • 2010-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多