Php – Let IIS 7 return php files as simple html file

http-status-code-404iisPHP

I have a virtual server (Windows 2008 R2) with IIS 7.5 and a xxx.php file in one of my websites. This php file contains no php-code and I don't want to install any php-module, I only want the server to return the content of the php file as if it was a normal .html file.

I have a file with the same content named xxx.html in the same directory and that works, but instead of the php file I get a 404 error.

Any ideas?

Update

It's a system that was ported from php to asp.net mvc. Many users have a bookmark to this file and that's why I want to keep it (with the extension). But I found a different way by using using routes in asp.net mvc. Still funny that you cannot configure IIS to simply return php files the same way as html files.

Best Answer

If you don't have a PHP interpreter installed in IIS, it will simply not recognize the file, so it will not be able to make any use of it. If you want IIS to handle a PHP file just like it was a plain text one, you'll need to register its MIME type, so that IIS will know what to do with it.

Please use the instructions provided here: http://technet.microsoft.com/en-us/library/cc725608(v=ws.10).aspx.

The file extension should be, of course, .php; the MIME type should be text/plain.

Please note that doing so will not allow you to use PHP on this server anymore, as it will always handle PHP files like plain text ones, after configuring this setting. If you want to actually use PHP, then you should install and register a PHP interpreter.