2

以下列出了能够执行 PHP 的扩展:

AddType application/x-httpd-php5 .php .php5

如何只允许一个特定文件能够运行 PHP?

以下不起作用:

AddType application/x-httpd-php5 example\.php9
4

2 回答 2

2

您不能将文件名添加到AddType指令中。只允许文件扩展名。要将 php 处理程序添加到单个文件,您可以使用以下命令:

 RewriteEngine on

 RewriteRule ^thisfile\.php$ - [H=application/x-httpd-php5]

或者<filesMatch>

<filesMatch "^thisfile\.php$">
AddType application/x-httpd-php5 .php
</filesMatch>

参考 :

Mod重写标志

https://httpd.apache.org/docs/2.4/rewrite/flags.html#flag_h

文件匹配

https://httpd.apache.org/docs/2.4/mod/core.html#filesmatch

于 2019-02-20T07:12:46.313 回答
0

您应该在 htaccess 中使用重写规则。

 RewriteRule ^example\.php9/?$ exmaple.php
于 2019-02-20T06:32:45.983 回答