2

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.

4 Answers 4

1

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.

1
  • Your answer makes sense. Thank you and thank you to everybody else here who tried to help me.
    – Preli
    Jul 30, 2012 at 15:03
1

Just rename it to a .htm or .html file? You can't properly serve PHP files without PHP installed... And why is the file a .php file if it doesn't have PHP code in it anyway? What you're asking is daft, you either install and use PHP or you don't.

Edit

Fair enough, it's one of those nuisance things you have to accomplish to accommodate legacy systems. Another way you could do it would be to install PHP then create a small php redirect script, not a perfect solution but a workable one.

2
  • 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.
    – Preli
    Jul 30, 2012 at 8:39
  • You can, see my answer.
    – Massimo
    Jul 30, 2012 at 8:43
1

Your server must be configured to understand and allow php files.

Please follow this tutorial to enable php: click

If you want to allow specific file extension follow this guide: click

2
1

To serve a PHP as plain HTML you just need to map the .php extension to the HTML MIME type. In IIS Manager: MIME Types > Add... Enter the following in the dialog that opens (without the quotes): File name extension: "php", MIME type: "text/html".

You can do this at the Server, Site, or Application level.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .