4

I have the following line in .htaccess

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

And it used to work for years to treat html pages as php, however recently I noticed it is not working anymore, except only in the homepage (example.com), and not even at the same page (example.com/index.html)

I tried now to add the following to /etc/apache2/mods-enabled/php5.6.conf and restarted apache, but still it didn't work. Also tried other suggestions here, but still no luck.

<FilesMatch ".+\.html$">
    SetHandler application/x-httpd-php
</FilesMatch>

Any idea what could have happened? Or how to fix that?

Mike
  • 143
  • 1
  • 1
  • 3
  • 1
    Something like this suddenly stopping working is typical of a server upgrade; but by the sounds of it, this is your own server and nothing has changed? Or have you changed the version of PHP being used? What do you mean by: "except only in the homepage (`example.com`), **and not even at the same page** (`example.com/index.html`)"? – MrWhite Feb 09 '19 at 00:50
  • I thought the problem was for encoding or particular files, but the `index.html` is the same in the above note, so how is it working on the domain name, but not it's `index` file, which is the exact same! (Of course along with not working in the whole site). – Mike Feb 09 '19 at 00:54
  • Ah, you're saying `example.com/` works (ie. loads `index.html` and processes as PHP), but a direct request to `example.com/index.html` does not? And you don't have a `index.php` in there as well? `example.com/` results in mod_dir loading `index.html` via an internal subrequest - that is the difference (although I don't know why that would make a difference). – MrWhite Feb 09 '19 at 01:01
  • Yes, don't have an `index.php`, it's just `index.html`. – Mike Feb 09 '19 at 01:03
  • Do you have many `.html` files? May not be what you had in mind, but my preference would be to use the correct file extension for these files and use URL-rewriting to rewrite the `.html` request to the underlying filesystem (ie. to `.php`). This is more reliable cross server and altogether more flexible IMO. – MrWhite Feb 09 '19 at 01:05
  • That's an idea right, but I just wanted to understand the issue before doing something like that.. – Mike Feb 09 '19 at 01:09

1 Answers1

2

Find out your handler by creating a PHP file with following contents

<?php echo $_SERVER['REDIRECT_HANDLER']; ?>

When opened from browser, it will return the handler name for php. Then replace your current htaccess code with correct handler. For example, if your output is application/x-httpd-php5, then your htaccess will look like this:

<FilesMatch ".+\.html$">
SetHandler application/x-httpd-php5
</FilesMatch>

Reference: https://stackoverflow.com/a/49375772/2703813

peterh
  • 4,953
  • 13
  • 30
  • 44
Shahriar Shojib
  • 332
  • 1
  • 2
  • 11