【问题标题】:How to set .htaccess in order to block certain URLs? [duplicate]如何设置 .htaccess 以阻止某些 URL? [复制]
【发布时间】:2016-09-25 00:06:19
【问题描述】:

这是我的网站组织:

index.php 包括页眉、主页和页脚文件:

我应该如何设置 .htaccess 以便 MyWebSite/ 是唯一允许的 URL?

【问题讨论】:

  • 你用的是什么版本的apache?
  • @Panama Jack 不知道,上一版MAMP提供的那个

标签: php .htaccess url web


【解决方案1】:

你可以这样试试。阻止除 localhostserver IP address 之外的所有 php 文件。

对于 Apache

<Files ~ "\.php">
    Order Deny,Allow
    Deny from all
    Allow from 127.0.0.1
</Files>

<Files "index.php">
    Order Allow,Deny
    Allow from all
</Files>

对于 Apache >= 2.4

<Files ~ "\.php">
    Require all denied
    Require ip 127.0.0.1
</Files>

<Files "index.php">
    Require all granted
</Files>

Mamp 应该使用 Apache 2.4,所以第二个示例应该可以工作。

【讨论】:

  • 非常感谢先生,它让我知道我的 apache 也是
  • 没问题,很高兴它成功了。从技术上讲,这与其他问题并不重复,因为它并没有真正提供相关的答案。
  • 确实,我的问题更具体,您的答案也是如此。如果两个线程都链接起来,它将帮助遇到同样问题的人。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多