简体   繁体   English

仅为特定文件而不是特定扩展名的所有文件启用 PHP

[英]Enable PHP for only a specific file instead of all files of a specific extension

Using Apache it's easy to enable PHP for all files of any extension:使用 Apache 很容易为任何扩展名的所有文件启用 PHP:

AddHandler application/x-httpd-php .css .js .txt .xml

How do I enable PHP for only a specific file but not all other files with that same extension?如何仅为特定文件启用 PHP,而不为具有相同扩展名的所有其他文件启用 PHP?

I have tried AddHandler application/x-httpd-php test.xml and it did not work and the search engines aren't coughing up anything remotely relevant.我已经尝试过AddHandler application/x-httpd-php test.xml并且它没有工作并且搜索引擎没有咳出任何远程相关的东西。

AddHandler can be used inside a <Files> container. AddHandler可以在<Files>容器内使用。

AddHandler Directive AddHandler指令

  • Description: Maps the filename extensions to the specified handler 说明:将文件扩展名映射到指定的处理程序
  • Context : server config, virtual host, directory , .htaccess 上下文 :服务器配置,虚拟主机, 目录 ,.htaccess

... where directory stands for: ... directory代表:

directory 目录

A directive marked as being valid in this context may be used inside <Directory>, <Location>, <Files> , <If>, and <Proxy> containers in the server configuration files, subject to the restrictions outlined in Configuration Sections. 在配置上下文中概述的限制下,可以在服务器配置文件的<Directory>,<Location>, <Files> ,<If>和<Proxy>容器内使用在此上下文中标记为有效的指令。

And <Files> can be used from .htaccess just fine: 可以从.htaccess使用<Files>很好:

<Files> Directive <文件>指令

  • Description: Contains directives that apply to matched filenames 描述:包含适用于匹配文件名的指令
  • Context: server config, virtual host, directory, .htaccess 上下文:服务器配置,虚拟主机,目录, .htaccess

Simply:简单地:

<Files hello.html>
AddType application/x-httpd-php .html
</Files>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM