ez007
ez007

Reputation: 147

Parsing HTML files as PHP

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

Upvotes: 2

Views: 5672

Answers (3)

kevinandrada
kevinandrada

Reputation: 499

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

Upvotes: 0

Sujit Agarwal
Sujit Agarwal

Reputation: 12508

RewriteEngine on 
RewriteRule ^(.*)\.htm $1\.php

Upvotes: 2

user562854
user562854

Reputation:

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

Upvotes: 3

Related Questions