0

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

user209835
  • 161
  • 2
  • 11

2 Answers2

1

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.

Community
  • 1
  • 1
Jon Weers
  • 1,604
  • 17
  • 27
  • Thank you, Jon. Your suggestion to 301 redirect .html requests is certainly pragmatic and perhaps the best route for me to go. I was just flummoxed, because before MAMP Pro I used the Mac's native Apache and PHP. In that environment, AddHandler directives worked fine for similar site update projects. I figured it was some small nuance of syntax I was missing, to target MAMP's fastCGI module. I am NOT about to start hacking MAMP's Apache config files! Thanks again for your time and your suggestion. Steve – user209835 May 07 '15 at 18:10
1

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.

LSE
  • 1,075
  • 1
  • 8
  • 10