Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

apache

Using Apache it's easy to enable PHP for all files of any extension:

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?

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.

like image 945
John Avatar asked Feb 01 '26 07:02

John


1 Answers

AddHandler can be used inside a <Files> container.

AddHandler Directive

  • Description: Maps the filename extensions to the specified handler
  • Context: server config, virtual host, directory, .htaccess

... where directory stands for:

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.

And <Files> can be used from .htaccess just fine:

<Files> Directive

  • Description: Contains directives that apply to matched filenames
  • Context: server config, virtual host, directory, .htaccess
like image 189
Álvaro González Avatar answered Feb 02 '26 20:02

Álvaro González