How do I force other file extensions to load as PHP?


This article explains how to force PHP to load a file that does not end with the extension .php.

Using an .htaccess file

To process files with PHP whose names don't end with .php, you can use a directive in .htaccess.

For example, create a file named myfile.test with the following code:

echo 'testing an extension using PHP';

The extension .test doesn’t exist. But, you can force it to run as PHP by adding this code to your .htaccess file:

AddHandler fcgid-script .test
FcgidWrapper "/dh/cgi-system/php74.cgi" .test

If you load the file in a browser, it will now load as a normal PHP file.


In the above example, files with the extension .test are using PHP 7.4 with FastCGI.

If you do not want to change the version of PHP but want PHP to use CGI (instead of FastCGI), use this line in your .htaccess file:

AddHandler php-cgi .test

If you use the php5-cgi directive in a FastCGI environment you'll force all PHP code in the specified extensions to be run using CGI regardless of what option you choose in the panel.

See also

Did this article answer your questions?

Article last updated PST.

Still not finding what you're looking for?