Linux – AddHandler for PHP with different file extension

.htaccessApache2linuxPHP

I'm trying to configure a hosted Apache server, via .htaccess, to execute files with .asp extension with PHP. But I don't know what the correct handler-name for AddHandler is.

The reason is that we have a flash app that is GET requesting .asp files. We will re-write the .asp files in PHP but we can not change the flash app (we don't even have the source code).

I have tried to use the AddHandler and AddType directives.

AddHandler php-fcgid .php .asp
AddType application/x-httpd-php .asp
AddHandler application/x-httpd-php7 .asp

Examples of directives I have tried to no avail

Most give No input file specified. or set the mime-type to application/x-httpd-php for .php files (technically setting the Content-Type HTTP header).

Now, I fully understand AddHandler and AddType – the best resource I have found is https://www.webmasterworld.com/apache/4557229.htm#msg4557505.

The host has, what looks like a custom dash-board for administrating the server. I can change PHP version, from 5.4 to 7.0 and change some settings in php.ini.

I uploaded a phpinfo(); and some of the values I think is relevant is posted below. The Apache version is unknown as it just report Server: Apache. But I'm sure it is at least Apache2, since Apache 2.0 Handler is listed under SAPI Modules.

How can I figure out what the correct handler-name for AddHandler is?

PHP Version 7.0.9

Server API  CGI/FastCGI
Configuration File (php.ini) Path   /compile/php70/dest/lib
Loaded Configuration File   /etc/custom_php_config/slavespillet.dk/php.ini
Scan this dir for additional .ini files     (none)
Additional .ini files parsed    (none)
PHP API     20151012

cgi-fcgi

Directive   Local Value Master Value
cgi.check_shebang_line  1   1
cgi.discard_path    0   0
cgi.fix_pathinfo    1   1
cgi.force_redirect  1   1
cgi.nph 0   0
cgi.redirect_status_env no value    no value
cgi.rfc2616_headers 0   0
fastcgi.logging 1   1

Core

PHP Version     7.0.9
$_SERVER['SERVER_SOFTWARE'] Apache

Best Answer

A workaround/alternative is to simply rewrite the .asp request to .php and store your files as ordinary .php files - assuming .php files are served correctly. Using mod_rewrite you could do something like the following in your root .htaccess file:

RewriteEngine On
RewriteRule ^(.+)\.asp$ $1.php [L]

This would internally rewrite a request for /path/to/something.asp to /path/to/something.php.