【问题标题】:Why does Apache execute php file on calling file without extension为什么Apache在没有扩展名的调用文件上执行php文件
【发布时间】:2012-04-21 03:22:58
【问题描述】:

今天我在我的服务器上发现了一个奇怪的东西。 我创建了一个 php 文件(test.php)并在其中编写了一些 php 代码。然后我使用

调用它
http://127.0.0.1/test

并且执行了“test.php”!没有 .php 时如何理解运行 test.php ? 我的根目录上没有 htaccess 文件来告诉 apache 这样做。 我想这可能会导致安全问题。我该如何预防?

我的操作系统是 ubuntu,网络服务器是 Apache2。

【问题讨论】:

  • 这如何导致安全问题?如果有人可以访问 example.com/test,他们也可以访问 example.com/test.php。

标签: php apache apache2


【解决方案1】:

这是因为 MultiViews(它在该目录的“选项”中的某处启用)。

查看此处:http://httpd.apache.org/docs/current/content-negotiation.html#negotiation 了解其工作原理的详细信息。

【讨论】:

  • 确实是这个原因。
【解决方案2】:

检查你的 apache 配置(/etc/apache2/sites-available/[site_name or default]),它可能包含 mod_rewrite 指令,例如:

RewriteEngine on
RewriteBase /
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(([^/]+/)*[^.]+)$ /$1.php [L]

如果你用 # 注释掉它们并重新启动 apache,在不指定扩展名的情况下访问 /test 将不再有效。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-13
    • 1970-01-01
    • 2021-11-30
    相关资源
    最近更新 更多