仅允许特定文件通过htaccess运行PHP

仅允许特定文件通过htaccess运行PHP,php,apache,.htaccess,Php,Apache,.htaccess,下面列出了能够执行PHP的扩展: AddType application/x-httpd-php5 .php .php5 如何只允许一个特定文件运行PHP 以下操作不起作用: AddType application/x-httpd-php5 example\.php9 您应该在htaccess中使用重写规则 RewriteRule ^example\.php9/?$ exmaple.php 您不能将文件名添加到AddType指令。只允许使用文件扩展名。要将php处理程序添加到单个文件,可

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

AddType application/x-httpd-php5 .php .php5
如何只允许一个特定文件运行PHP

以下操作不起作用:

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

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

 RewriteRule ^example\.php9/?$ exmaple.php

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

 RewriteEngine on

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


AddType应用程序/x-httpd-php5.php
参考:

修改重写标志

文件匹配

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