There is a problem with PHP parsing the html files on my site.
I've been using php in html files, together with the directive
AddHandler application/x-httpd-php5 .html .htm
in the .htaccess file, without any problem for 5 years.
Since a couple of days ago, suddenly it doesn't work anymore.
Only the .php files are parsed properly and the html files are not, anymore
(the actual php code is displayed instead of the result of the execution!)
I contacted the host service but they say they can't offer support.
I thought that for some reason the .htaccess file is not read anymore by the server,
but I tested it with a redirect directive and it worked.
Then I thought that they modified something in the php engine and beside the above mentioned directive I've tried each of the following directives:
AddHandler application/x-httpd-php .html .htm
AddType application/x-httpd-php5 .html .htm
AddType application/x-httpd-php .html .htm
AddHandler x-mapp-php5 .html .htm
but no success.
So html file are not php parsed anymore, but I've noticed someting interesting about the index.html file:
if I access mydomain.com/index.html the result is bad,
HOWEVER, if I access just mydomain.com then it displays properly !!
(And of course, there is no index.php file). That means the index.html file is actually parsed, in this case.
BUT, the situation stays the same even if the .htaccess file is deleted.
For this particular file (index.html), the behavior is the same in any of the subdirectories.
As the hosting service is not helpful with checking their server configuration settings,
I wonder if there is anything I can try on my side, as I'm stuck with this.
And any hints would be welcome.
Thanks.
Related
I have a problem related to calling PHP from within HTML files at HostGator. Suddenly, the site was giving a 404 error on my primary page, INDEX.HTML. After some troubleshooting, I realized that it was because the AddHandler statement in the .htaccess file was no longer being recognized. I commented it out by using a "#". Doing this avoided the 404 error for the INDEX.HTML page, but the page didn't display anything that was dependent on a call to PHP. This is the commented-out statement in the .htaccess file. The front line support folks were unaware of any change on the servers.
#AddHandler application/x-httpd-ea-php74 .php .php7 .phtml .html .htm
By the way, my .htaccess file is located in the PUBLIC_HTML folder.
As it turns out, after 10 days HostGator informed me that they indeed upgraded from PHP-74 to LS-PHP-74 (Lite Speed). They had not informed their front line support after they made the upgrade. A different AddHandler statement was required in .htaccess.
Original Statement:
AddHandler application/x-httpd-ea-php74 .php .php7 .phtml .html .htm
With LS-PHP-74 the statement has to be modified to:
AddHandler application/x-httpd-ea-php74___lsphp .php .php7 .phtml .html .htm
That allowed PHP to be called from within HTML files again.
Yep. they broke my Angular APP routing last night!, thanks HostGator!.
PD: 4 AM the first RING!. --- Hey what happened, it reads not found?.
So I'm trying to configure my .htaccess file so that it can runs the PHP code inside the HTML files.
When I go to mysite.com/thefile.php, it runs it correctly without any problem. Same if I go to mysite.com/thefile.html. But if I add <?php echo "Hello"; ?> inside the HTML file, it doesnt display anything. In fact, when I right click "View source code", it displays the php lines.
Here's what I tried with my .htaccess file:
RemoveHandler .html .htm
AddType application/x-httpd-php .php .html .htm
I also a tried with just
AddType application/x-httpd-php .php .html .htm
But it displays a "500 Internal Server Error" that says:
The server encountered an internal error or misconfiguration and was unable to complete your request.
The most common causes of this problem are errors in the app's .htaccess file or incorrect file or directory permissions preventing the web server from reading the .htaccess file.
More information about this error is available in the app's Apache error log at:
/srv/users/SYSUSER/log/APPNAME/APPNAME_apache.error.log
I'm quite new to web development in general, and I want to mention that, except from these 2/1 lines in the .htaccess file, I have nothing else. Maybe I'm missing some lines in it? Just a guess
Thanks guys (and gals if they exist!)
With Ubuntu/Apache 2.4.x, in your /etc/apache2/mods-enabled/php7.1.conf or equivalent, you could add:
<FilesMatch ".+\.html$">
SetHandler application/x-httpd-php
</FilesMatch>
(But you shouldn't do this at all! Use .php files for PHP code.)
I am designing a website that requires me to show the outputs of a mysql database on a webpage written in html. However my browser doesn't seem to recognize the php scripts within the html file and returns blank values where their should be details. The scripts worked fine in the .php files but have no effect when included in the .html files even after creating a .htaccess file as instructed in previously asked questions. Is there anything else that can be done to solve this issue?
There are two methods (that I've encountered) of changing the environment on an Apache server via .htaccess to allow PHP scripts to be processed in .html files, depending on the configuation. Whichever of these you've attempted, try the other.
AddHandler application/x-httpd-php5 .php .html .htm
Or
AddHandler cgi-script .html
SetEnv PHP_EXTENSION .html
I have few files whose extension is htm that i want to run as php using htaccess code
this is the htaccess code that i am using
AddHandler application/x-httpd-php5 .htm .php .html
this code work fine but now i change my hosting server in that this code not working.
i tried all these code but no one work
AddHandler application/x-httpd-php .htm .php .html
AddType application/x-httpd-php .html .htm
AddType application/x-httpd-php5 .html .htm
my new server says
cPanel Linux Hosting packages only support the SymLinksIfOwnerMatch option in the .htaccess file.
Please point me in right direction how can i run htm file as php on my server
I'm afraid it's a no-go then... If your hosting blocks the appropriate directives in your .htaccess, your only way to go would be to either blackmail or hack the provider, or change the extension from .htm to .php. As this is really a server-administration thing, and if the server administrator doesn't allow you, there is no way you can go around it...
A hacky solution would be to use rewrites to route .htm to .php files. But still then you'd need to rename your files from .htm to .php. This could be a solution if you're app routing isn't setup dynamically and your main concern is that the url's should not be changed. Although changed url's can be caught with 301 redirects.
I'm stuck trying to figure out what directives my htaccess file for a directory needs. To give a little background, I was messing around with AddType and AddHandler to try to get html files to run php in them. I was adding directives like:
AddType application/x-httpd-php .php .html
and
AddType application/x-httpd-php5 .php .html
That didn't work, so I tried adding handlers as well:
AddHandler x-httpd-php .php .html
and
AddHandler application/x-httpd-php .php .html
That still didn't give me what I wanted so I tried many combinations, like:
AddType application/x-httpd-php .php .html
AddHandler php-script .php .html
I even tried combinations with SetHandler
AddType application/x-httpd-php .php .html
AddHandler php-script .php .html
SetHandler application/x-httpd-php .php html
I tried every imaginable combination of AddType and AddHandler found on the web.
!===== This is important ======!
I realized that its not good practice to have php run your html files just so you can run php in the html. I am no longer trying to do that. The only reason I'm posting this part above is to give you an idea on some things I've changed. These changes were made to the htaccess file at a directory above the root.
!==============================!
Now that I'm no longer trying to run my php in html files I cleared the AddType, AddHandler, and SetHandler directives from the htaccess file. But now I get an internal server error when trying to run php files.
So I tried putting some stuff back. If I had a handle, the browser now downloads the php instead of running it.
I should note that any php running below the directory I changed works fine. But everything in that directory or subdirectory of that directory has this same problem with php files.
I have tried deleting the htaccess file in that directory, but that does not work, I get an internal error.
If I turn Override off, I get an internal error.
Something I changed is persisting in that directory and I'm wondering how to either
a. turn it off
b. add the correct handler to that htaccess file so that php files are run again (like they are on the rest of the server)
I did have the exact same issue so I deleted all the content of .htaccess and started trying only with handlers until I figured it out. My local .htaccess copy had the following SetHandler:
AddHandler x-httpd-php5-3 .php
In my case it worked after changing it to:
AddHandler application/x-httpd-php5 .php
It seems the whole trick is only the handler, I tried this solution in 2 different servers with different configurations and in both cases just changing AddHandler worked. If this doesn't work for you try a different handler for php.
Hope it helps.
Just realized I left this up unanswered after I solved the problem. If someone has a similar problem and is reading this : Check the permissions on all associated folders. I can't remember the specifics but one of the directories involved (I believe it was the htaccess directory) had permissions that persisted after changing some things and then changing them back.