2

Is this the correct way to parse html files as php?

RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html

Saved in a .htaccess file in my root folder?

I am adding in a navigation bar that is called in via php and this would save renaming all my html files!

Thanks

ez007
  • 135
  • 2
  • 12
  • 6
    When you tried it, did it work? – Matti Virkkunen Jun 04 '11 at 13:38
  • OK, now, some fresh programmer comes along which accidentally borks your .htaccess for some new feature. Result: all your code is plainly downloadable. Avoid this if you can, and if you must, please add it at a more safe point like apache/httpd.conf or vhost configuration. – Wrikken Jun 04 '11 at 13:48
  • @Wrikken so i shouldn't use this method at all? – ez007 Jun 04 '11 at 14:09
  • Not unless you have a _very_ compelling reason to do it. And I cannot think of any atm, you might have one? – Wrikken Jun 04 '11 at 23:14

3 Answers3

3

Yes, if your webserver is running php as Apache module.

If your webserver is running PHP as CGI, use this instead:

AddHandler application/x-httpd-php .html .htm 

Or, you could use this simple rewrite rule:

RewriteEngine on 
RewriteRule ^(.*)\.html $1\.php
  • Thank you. Yes it is running php as Apache. Is this a safe method to use? – ez007 Jun 04 '11 at 14:14
  • Yes it is completely safe as long as you keep your source code in .php files and not vice versa. –  Jun 04 '11 at 14:16
2
RewriteEngine on 
RewriteRule ^(.*)\.htm $1\.php
Sujit Agarwal
  • 12,348
  • 11
  • 48
  • 79
0

In my case, I wanted to parse HTML files as PHP so I added the code you mentioned on my .htaccess which is:

AddType application/x-httpd-php .html

It worked on my localhost as intended since I'm using WAMP but on my server, which is hosted in Drupion this does not work. My HTML files became downloadable.

The answer here gave me an idea on how to fix the problem.

Basically, you need to know the "handler-name" your server is using to parse PHP. Then you can add similar code on your .htaccess.

AddHandler fcgid-script .html
FCGIWrapper /home/example/fcgi-bin/php5.fcgi .html
Community
  • 1
  • 1
kevinandrada
  • 449
  • 2
  • 5
  • 14