user209835
user209835

Reputation: 161

can't parse PHP in .html docs, MAMP Pro

I need to parse PHP directives in files with an .html extension (I'm updating a legacy site and wish to avoid broken links). Lots of tips and solutions exist, none of which are working for me locally using MAMP Pro 3, latest version (3.2.1).

I set the PHP version to 5.4.39 Otherwise, all other MAMP settings are default (including loading fastCGI module).

AllowOverride, Order and Allow from are all checked.

I created an .htaccess file which apparently IS being read because other things (custom 404 page for example) work.

Suggestions I found via search and have tried which don't work include:

AddHandler php5-cgi .html .htm

and

AddHandler application/x-httpd-php .html

(Plus AddType variations of the above, which prompted the browser to download the document.)

My project lives in a subdirectory of the MAMP htdocs folder. The .htaccess file is in the root of the project subdirectory if that makes any difference. Mac OS 10.9.5 if that makes any difference.

Any thoughts on how to get this seemingly straightforward thing to work in MAMP? Thanks. Steve

Upvotes: 0

Views: 1666

Answers (2)

LSE
LSE

Reputation: 1358

For MAMP Pro, this works:

AddHandler php-fastcgi .html

For future reference:
I found a lot of variations of this on a google search, but nothing worked(at least for the first 10 pages). When I was almost giving up, I tried a text search for 'handler' in my <?php phpinfo(); ?> output and found this:

$_ENV['REDIRECT_HANDLER']   php-fastcgi

So I swapped the usual application/x-httpd-php with php-fastcgi and voila !

This took me more hours that I care to admit, so hopefully it will help someone.

Upvotes: 2

Jon Weers
Jon Weers

Reputation: 1641

The AddHandler rules can be specific to each Apache + PHP install, and an apache restart might be necessary before the change will go in effect. See this other post for more options to try: Server not parsing .html as PHP.

However, a more common solution would be to use the .php suffix on any files you want PHP to parse, then use .htacceess rules to 301 redirect any old html links to their new php counterparts.

RewriteRule ^(.*).html? $1.php [R=301]

This has the advantage of telling browsers to update any bookmarks with the new URLs.

Upvotes: 1

Related Questions