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.

Alex Berry
  • 2,307
  • 13
  • 23
Preli
  • 123
  • 1
  • 1
  • 6

4 Answers4

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

mnmnc
  • 203
  • 1
  • 8
  • I don't want to enable php – Preli Jul 30 '12 at 08:39
  • Follow this tutorial to enable .php file extension to be recognized on your server http://www.iis.net/ConfigReference/system.webServer/security/requestFiltering/fileExtensions/add – mnmnc Jul 30 '12 at 09:18
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.

Alex Berry
  • 2,307
  • 13
  • 23
  • 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 '12 at 08:39
  • You can, see my answer. – Massimo Jul 30 '12 at 08:43
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.

Massimo
  • 68,714
  • 56
  • 196
  • 319
  • Your answer makes sense. Thank you and thank you to everybody else here who tried to help me. – Preli Jul 30 '12 at 15:03
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.

jkarpilo
  • 71
  • 5