Allow only specific file to run PHP via htaccess Allow only specific file to run PHP via htaccess apache apache

Allow only specific file to run PHP via htaccess


You can not add filename to AddType directive. Only file extensions are allowed. To add php handler to a single file you can use this :

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

Or <filesMatch>

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

Reference :

Mod-rewrite flags

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

filesMatch

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


You should use rewrite rule in htaccess.

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