Using PHP sessions alongside HTML? [duplicate] - php

I need to run all of my .html files as .php files and I don't have time to change all of the links before our presentation tomorrow. Is there any way to "hack" this with my Apache server?

Create a .htaccess file at the root of your website and add this line:
[Apache2 # Ubuntu/Debian: use this directive]
AddType application/x-httpd-php .html .htm
Or, from comment below:
AddType application/x-httpd-php5 .html .htm
If your are running PHP as CGI (probably not the case), you should write instead:
AddHandler application/x-httpd-php .html .htm

In My Godaddy Server the following code worked
Options +ExecCGI
AddType application/x-httpd-php .php .html
AddHandler x-httpd-php5 .php .html

This is in edition to all other right answers:
If you are not able to find the correct Handler, Simply create a .php file with the following contents:
<?php echo $_SERVER['REDIRECT_HANDLER']; ?>
and run/open this file in browser.
Use this output in .htaccess file
Create a .htaccess file at the root of your website(usually a folder named public_html or htdocs on linux servers) and add this line:
AddType [[THE OUTPUT FROM ABOVE FILE]] .html .htm
Example
AddType application/x-httpd-php70 .html .htm
Important Note:
If you see blank page or Notice: Undefined index: REDIRECT_HANDLER
Try default in .htaccess
AddHandler application/x-httpd-php .html

You may also use the H or T flag of mod_rewrite to force all .html files to be parsed by php handler :
using H (Handler) flag:
RewriteEngine on
RewriteRule \.(html|htm)$ - [H=application/x-httpd-php5]
using T (Type) flag :
RewriteEngine on
RewriteRule \.(html|htm)$ - [T=application/x-httpd-php5]
Or you can add more extensions to the rule pattern seprated by a pipe | that you want to be parsed by php handler
ex :
RewriteRule \.(html|htm|txt|foo)$ - [T=application/x-httpd-php5]
the example above will change the mime type of files that end with .html , .htm , .txt , .foo to php.
Note : on some servers you will have to change php5 to php to get this example to work in handler string:
Change it
[T=application/x-httpd-php5]
to
[T=application/x-httpd-php]

You need to add the following line into your Apache config file:
AddType application/x-httpd-php .htm .html
You also need two other things:
Allow Overridding
In your_site.conf file (e.g. under /etc/apache2/mods-available in my case), add the following lines:
<Directory "<path_to_your_html_dir(in my case: /var/www/html)>">
AllowOverride All
</Directory>
Enable Rewrite Mod
Run this command on your machine:
sudo a2enmod rewrite
After any of those steps, you should restart apache:
sudo service apache2 restart

For anyone out there still having trouble,
try this (my hosting was from Godaddy and this is the only thing that worked for me among all the answers out there.
AddHandler x-httpd-php5-cgi .html

I think this is the best way to run php script on html and htm pages:
AddType application/x-httpd-php5 .html .htm

Normally you should add:
Options +ExecCGI
AddType application/x-httpd-php .php .html
AddHandler x-httpd-php5 .php .html
However for GoDaddy shared hosting (php-cgi), you need to add also these lines:
AddHandler fcgid-script .html
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .html
Source: Parse HTML As PHP Using HTACCESS File On Godaddy.

Running .html files as php stopped working all of a sudden in my .htaccess file.
Godaddy support had me change it to:
AddHandler application/x-httpd-lsphp .html

here put this in your .htaccess
AddType application/x-httpd-php .php .htm .html
more info on this page

Using #Marc-François approach Firefox prompted me to download the html file
Finally the following is working for me (using both):
AddType application/x-httpd-php .htm .html
AddHandler x-httpd-php .htm .html

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

I'm using PHP7.1 running in my Raspberry Pi 3.
In the file /etc/apache2/mods-enabled/php7.1.conf I added at the end:
AddType application/x-httpd-php .html .htm .png .jpg .gif

On Dreamhost Servers you can refer to this page that at time of writing indicates you may use the following for php 7.2 with FastCGI:
AddHandler fcgid-script .html
FcgidWrapper "/dh/cgi-system/php72.cgi" .html
Or if you are using php5 cgi (not FastCGI):
AddHandler php5-cgi .html

None of the answers posted here worked for me.
In my case the problem was, by the one hand, that the .conf file (/etc/apache2/sites-available/default-ssl.conf or /etc/apache2/sites-available/000-default.conf) did not contain the directive AllowOverride All for the site directory, which caused the .htaccess to not been processed. To solve this, add:
<Directory /var/www/html/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
On the other hand, the problem was that the .htaccess was created by the root user, and therefore the apache user could not read it. So, changing the file owner solved definitely the problem:
chown www-data:www-data .htaccess

First, read this: https://httpd.apache.org/docs/current/howto/htaccess.html#when
Then read my post here: https://stackoverflow.com/a/59868481/10664600
sudo vim /etc/httpd/conf/httpd.conf

Sometimes it doesn't work, if you just add the .htaccess file to the directory. In my case, I also changed an entry in the apache2 configuration.
sudo nano /etc/apache2/apache2.conf
...
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
Modification:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
After that you only must restart the apache2-service:
sudo systemctl restart apache2
This worked for me.

This would help anyone,
RewriteEngine on
RewriteRule ^(.+)\.html$ $1.php [L]
Digitalocean
Thanks #FlamberHansen.

If you're on Plesk running PHP as an FPM application served by Apache this article worked for me:
Go to Domains > example.com > PHP Settings and add the following lines into the field Additional configuration directives:
[php-fpm-pool-settings]
security.limit_extensions = .php .phar .html .inc
.htaccess
<Files ~ .(?i:inc|html|htm)$>
SetHandler proxy:unix:///var/www/vhosts/system/EXAMPLE.com/php-fpm.sock|fcgi://127.0.0.1:9000
</Files>

Related

Is it possible to place PHP database connection logic inside HTML [duplicate]

I need to run all of my .html files as .php files and I don't have time to change all of the links before our presentation tomorrow. Is there any way to "hack" this with my Apache server?
Create a .htaccess file at the root of your website and add this line:
[Apache2 # Ubuntu/Debian: use this directive]
AddType application/x-httpd-php .html .htm
Or, from comment below:
AddType application/x-httpd-php5 .html .htm
If your are running PHP as CGI (probably not the case), you should write instead:
AddHandler application/x-httpd-php .html .htm
In My Godaddy Server the following code worked
Options +ExecCGI
AddType application/x-httpd-php .php .html
AddHandler x-httpd-php5 .php .html
This is in edition to all other right answers:
If you are not able to find the correct Handler, Simply create a .php file with the following contents:
<?php echo $_SERVER['REDIRECT_HANDLER']; ?>
and run/open this file in browser.
Use this output in .htaccess file
Create a .htaccess file at the root of your website(usually a folder named public_html or htdocs on linux servers) and add this line:
AddType [[THE OUTPUT FROM ABOVE FILE]] .html .htm
Example
AddType application/x-httpd-php70 .html .htm
Important Note:
If you see blank page or Notice: Undefined index: REDIRECT_HANDLER
Try default in .htaccess
AddHandler application/x-httpd-php .html
You may also use the H or T flag of mod_rewrite to force all .html files to be parsed by php handler :
using H (Handler) flag:
RewriteEngine on
RewriteRule \.(html|htm)$ - [H=application/x-httpd-php5]
using T (Type) flag :
RewriteEngine on
RewriteRule \.(html|htm)$ - [T=application/x-httpd-php5]
Or you can add more extensions to the rule pattern seprated by a pipe | that you want to be parsed by php handler
ex :
RewriteRule \.(html|htm|txt|foo)$ - [T=application/x-httpd-php5]
the example above will change the mime type of files that end with .html , .htm , .txt , .foo to php.
Note : on some servers you will have to change php5 to php to get this example to work in handler string:
Change it
[T=application/x-httpd-php5]
to
[T=application/x-httpd-php]
You need to add the following line into your Apache config file:
AddType application/x-httpd-php .htm .html
You also need two other things:
Allow Overridding
In your_site.conf file (e.g. under /etc/apache2/mods-available in my case), add the following lines:
<Directory "<path_to_your_html_dir(in my case: /var/www/html)>">
AllowOverride All
</Directory>
Enable Rewrite Mod
Run this command on your machine:
sudo a2enmod rewrite
After any of those steps, you should restart apache:
sudo service apache2 restart
For anyone out there still having trouble,
try this (my hosting was from Godaddy and this is the only thing that worked for me among all the answers out there.
AddHandler x-httpd-php5-cgi .html
I think this is the best way to run php script on html and htm pages:
AddType application/x-httpd-php5 .html .htm
Normally you should add:
Options +ExecCGI
AddType application/x-httpd-php .php .html
AddHandler x-httpd-php5 .php .html
However for GoDaddy shared hosting (php-cgi), you need to add also these lines:
AddHandler fcgid-script .html
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .html
Source: Parse HTML As PHP Using HTACCESS File On Godaddy.
Running .html files as php stopped working all of a sudden in my .htaccess file.
Godaddy support had me change it to:
AddHandler application/x-httpd-lsphp .html
here put this in your .htaccess
AddType application/x-httpd-php .php .htm .html
more info on this page
Using #Marc-François approach Firefox prompted me to download the html file
Finally the following is working for me (using both):
AddType application/x-httpd-php .htm .html
AddHandler x-httpd-php .htm .html
AddHandler application/x-httpd-php .php .html .htm
// or
AddType application/x-httpd-php .php .htm .html
I'm using PHP7.1 running in my Raspberry Pi 3.
In the file /etc/apache2/mods-enabled/php7.1.conf I added at the end:
AddType application/x-httpd-php .html .htm .png .jpg .gif
On Dreamhost Servers you can refer to this page that at time of writing indicates you may use the following for php 7.2 with FastCGI:
AddHandler fcgid-script .html
FcgidWrapper "/dh/cgi-system/php72.cgi" .html
Or if you are using php5 cgi (not FastCGI):
AddHandler php5-cgi .html
None of the answers posted here worked for me.
In my case the problem was, by the one hand, that the .conf file (/etc/apache2/sites-available/default-ssl.conf or /etc/apache2/sites-available/000-default.conf) did not contain the directive AllowOverride All for the site directory, which caused the .htaccess to not been processed. To solve this, add:
<Directory /var/www/html/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
On the other hand, the problem was that the .htaccess was created by the root user, and therefore the apache user could not read it. So, changing the file owner solved definitely the problem:
chown www-data:www-data .htaccess
First, read this: https://httpd.apache.org/docs/current/howto/htaccess.html#when
Then read my post here: https://stackoverflow.com/a/59868481/10664600
sudo vim /etc/httpd/conf/httpd.conf
Sometimes it doesn't work, if you just add the .htaccess file to the directory. In my case, I also changed an entry in the apache2 configuration.
sudo nano /etc/apache2/apache2.conf
...
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
Modification:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
After that you only must restart the apache2-service:
sudo systemctl restart apache2
This worked for me.
This would help anyone,
RewriteEngine on
RewriteRule ^(.+)\.html$ $1.php [L]
Digitalocean
Thanks #FlamberHansen.
If you're on Plesk running PHP as an FPM application served by Apache this article worked for me:
Go to Domains > example.com > PHP Settings and add the following lines into the field Additional configuration directives:
[php-fpm-pool-settings]
security.limit_extensions = .php .phar .html .inc
.htaccess
<Files ~ .(?i:inc|html|htm)$>
SetHandler proxy:unix:///var/www/vhosts/system/EXAMPLE.com/php-fpm.sock|fcgi://127.0.0.1:9000
</Files>

Pass values from php file to a html file. [duplicate]

I need to run all of my .html files as .php files and I don't have time to change all of the links before our presentation tomorrow. Is there any way to "hack" this with my Apache server?
Create a .htaccess file at the root of your website and add this line:
[Apache2 # Ubuntu/Debian: use this directive]
AddType application/x-httpd-php .html .htm
Or, from comment below:
AddType application/x-httpd-php5 .html .htm
If your are running PHP as CGI (probably not the case), you should write instead:
AddHandler application/x-httpd-php .html .htm
In My Godaddy Server the following code worked
Options +ExecCGI
AddType application/x-httpd-php .php .html
AddHandler x-httpd-php5 .php .html
This is in edition to all other right answers:
If you are not able to find the correct Handler, Simply create a .php file with the following contents:
<?php echo $_SERVER['REDIRECT_HANDLER']; ?>
and run/open this file in browser.
Use this output in .htaccess file
Create a .htaccess file at the root of your website(usually a folder named public_html or htdocs on linux servers) and add this line:
AddType [[THE OUTPUT FROM ABOVE FILE]] .html .htm
Example
AddType application/x-httpd-php70 .html .htm
Important Note:
If you see blank page or Notice: Undefined index: REDIRECT_HANDLER
Try default in .htaccess
AddHandler application/x-httpd-php .html
You may also use the H or T flag of mod_rewrite to force all .html files to be parsed by php handler :
using H (Handler) flag:
RewriteEngine on
RewriteRule \.(html|htm)$ - [H=application/x-httpd-php5]
using T (Type) flag :
RewriteEngine on
RewriteRule \.(html|htm)$ - [T=application/x-httpd-php5]
Or you can add more extensions to the rule pattern seprated by a pipe | that you want to be parsed by php handler
ex :
RewriteRule \.(html|htm|txt|foo)$ - [T=application/x-httpd-php5]
the example above will change the mime type of files that end with .html , .htm , .txt , .foo to php.
Note : on some servers you will have to change php5 to php to get this example to work in handler string:
Change it
[T=application/x-httpd-php5]
to
[T=application/x-httpd-php]
You need to add the following line into your Apache config file:
AddType application/x-httpd-php .htm .html
You also need two other things:
Allow Overridding
In your_site.conf file (e.g. under /etc/apache2/mods-available in my case), add the following lines:
<Directory "<path_to_your_html_dir(in my case: /var/www/html)>">
AllowOverride All
</Directory>
Enable Rewrite Mod
Run this command on your machine:
sudo a2enmod rewrite
After any of those steps, you should restart apache:
sudo service apache2 restart
For anyone out there still having trouble,
try this (my hosting was from Godaddy and this is the only thing that worked for me among all the answers out there.
AddHandler x-httpd-php5-cgi .html
I think this is the best way to run php script on html and htm pages:
AddType application/x-httpd-php5 .html .htm
Normally you should add:
Options +ExecCGI
AddType application/x-httpd-php .php .html
AddHandler x-httpd-php5 .php .html
However for GoDaddy shared hosting (php-cgi), you need to add also these lines:
AddHandler fcgid-script .html
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .html
Source: Parse HTML As PHP Using HTACCESS File On Godaddy.
Running .html files as php stopped working all of a sudden in my .htaccess file.
Godaddy support had me change it to:
AddHandler application/x-httpd-lsphp .html
here put this in your .htaccess
AddType application/x-httpd-php .php .htm .html
more info on this page
Using #Marc-François approach Firefox prompted me to download the html file
Finally the following is working for me (using both):
AddType application/x-httpd-php .htm .html
AddHandler x-httpd-php .htm .html
AddHandler application/x-httpd-php .php .html .htm
// or
AddType application/x-httpd-php .php .htm .html
I'm using PHP7.1 running in my Raspberry Pi 3.
In the file /etc/apache2/mods-enabled/php7.1.conf I added at the end:
AddType application/x-httpd-php .html .htm .png .jpg .gif
On Dreamhost Servers you can refer to this page that at time of writing indicates you may use the following for php 7.2 with FastCGI:
AddHandler fcgid-script .html
FcgidWrapper "/dh/cgi-system/php72.cgi" .html
Or if you are using php5 cgi (not FastCGI):
AddHandler php5-cgi .html
None of the answers posted here worked for me.
In my case the problem was, by the one hand, that the .conf file (/etc/apache2/sites-available/default-ssl.conf or /etc/apache2/sites-available/000-default.conf) did not contain the directive AllowOverride All for the site directory, which caused the .htaccess to not been processed. To solve this, add:
<Directory /var/www/html/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
On the other hand, the problem was that the .htaccess was created by the root user, and therefore the apache user could not read it. So, changing the file owner solved definitely the problem:
chown www-data:www-data .htaccess
First, read this: https://httpd.apache.org/docs/current/howto/htaccess.html#when
Then read my post here: https://stackoverflow.com/a/59868481/10664600
sudo vim /etc/httpd/conf/httpd.conf
Sometimes it doesn't work, if you just add the .htaccess file to the directory. In my case, I also changed an entry in the apache2 configuration.
sudo nano /etc/apache2/apache2.conf
...
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
Modification:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
After that you only must restart the apache2-service:
sudo systemctl restart apache2
This worked for me.
This would help anyone,
RewriteEngine on
RewriteRule ^(.+)\.html$ $1.php [L]
Digitalocean
Thanks #FlamberHansen.
If you're on Plesk running PHP as an FPM application served by Apache this article worked for me:
Go to Domains > example.com > PHP Settings and add the following lines into the field Additional configuration directives:
[php-fpm-pool-settings]
security.limit_extensions = .php .phar .html .inc
.htaccess
<Files ~ .(?i:inc|html|htm)$>
SetHandler proxy:unix:///var/www/vhosts/system/EXAMPLE.com/php-fpm.sock|fcgi://127.0.0.1:9000
</Files>

No output to screen [duplicate]

I have the included code in my .htaccess file but the php code I am attempting to include is not working.
Options +Includes
AddType text/html .htm .html
AddHandler server-parsed .htm .html
AddType application/octet-stream .vcf
AddOutputFilterByType DEFLATE text/html text/htm text/plain text/css text/php text/javascript application/x-javascript
Try:
AddType application/x-httpd-php .html .htm
UPDATE 1
It may be PHP version specific. If you're using PHP5 try:
AddType application/x-httpd-php5 .html .htm
UPDATE 2
Try:
RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html
Or here's yet another alternative way to do this:
<FilesMatch "\.html$">
ForceType application/x-httpd-php
</FilesMatch>
On Apache 2.2.22 (Ubuntu) with Php 5 add these lines to /etc/apache2/mods-enabled/php5.conf
<FilesMatch ".+\.html$">
SetHandler application/x-httpd-php
</FilesMatch>
and restart apache
sudo service apache2 restart
For godaddy shared hosting (php-cgi):
From http://sagarnangare.com/parse-html-as-php-using-htaccess-file-on-godaddy/
AddHandler fcgid-script .html
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .html
That's the only one that worked for me.
If you are using Plesk Control Panel:
PHP is running as an Apache module:
<IfModule mod_php5.c>
AddHandler php5-script .php .html .htm
AddType text/html .php .html .htm
</IfModule>
PHP is running as a FastCGI application:
<IfModule mod_fcgid.c>
<Files ~ (\.html)>
SetHandler fcgid-script
FCGIWrapper /var/www/cgi-bin/cgi_wrapper/cgi_wrapper .html
Options +ExecCGI
allow from all
</Files>
</IfModule>
PHP is running as a CGI application:
<Files ~ (\.html)>
SetHandler None
AddHandler php-script .html
Options +ExecCGI
allow from all
</Files>
Then
/usr/local/psa/admin/sbin/httpdmng --reconfigure-all
http://kb.odin.com/en/115773
VERY IMPORTANT that you must replace the "php5" to your OWN exact PHP version in the:
AddHandler application/x-httpd-php5 .html .htm
AddType application/x-httpd-php5 .html .htm
Because I have tried everithing in every way from all over the web, but nothing worked until I found a "MultiPHP Manager" menupoint under my CPanel, and under this I found out that my exact PHP version/name/id (or whatever it is called) was "ea-php56", so my working code is:
AddHandler application/x-httpd-ea-php56 .html .htm
AddType application/x-httpd-ea-php56 .html .htm
I have browsed all day the forums, comments, but I haven't found this very important information anywhere, so maybe You also have to look up your exact PHP version if it is not working!
If your server is using PHP5 then use this:
AddHandler application/x-httpd-php5 .html .htm
If it's not PHP5 then use
AddHandler application/x-httpd-php .html .htm
It worked for me on CPanel hosting.
If you are using some other linux hosting try this:
<IfModule mod_mime.c>
AddType application/x-httpd-php .html .php .htm
</IfModule>
Options +FollowSymlinks
For Godaddy server it worked for me
Options +ExecCGI
AddHandler fcgid-script .html
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .html
BenG, did any solution ever work for you?
this may help -- i found this topic confusing, because either statement worked for me in my local dev environment
AddHandler application/x-httpd-php .html .htm
or
AddType application/x-httpd-php .html .htm
after reading the apache documentation on both directives, it seems that you want to use AddType when adding a mime type not yet handled by apache, and AddHandler when you want apache to handle a file differently than its default handling of that file type. i may be wrong, but that does seem to be what the manual is saying.
so if you want apache to handle .html and .htm as if they were .php files then you would use the directive :
AddHandler application/x-httpd-php .html .htm
the .htaccess file you mention above is doing a few things, so maybe you could first verify that it does indeed tell apache to handle .htm and .html files as if they are .php files; then move on to the other directives you want to use.
I was stumped for 2 hours until I looked into /etc/php/7.2/fpm/pool.d/www.conf and then uncommented the security setting to force php to only parse php and added .html so that the line now is security.limit_extensions = .php .php3 .php4 .php5 .php7 .html and then sudo service php7.2-fpm restart and doing the
<head>
</head>
<body>
This should show date here:
<?php echo date('l, F jS, Y'); ?>
</body>
and saved as test.html worked fine and displayed!
From http://support.lunarpages.com/knowledge_bases/article/321
How can I configure Apache to treat
.html files as PHP under suPHP? You
need to remove any previous entries
for handling .html files as PHP and
insert the following in your .htaccess
file: AddHandler x-httpd-php .html
.htm Or you can add this manually
using Cpanel -> Apache Handlers ->
New: Extension: .html .htm Handler:
x-httpd-php The newest cPanel servers
actually require the following
instead: AddHandler
application/x-httpd-php .html .htm or
AddType application/x-httpd-php .html
.htm Please try this if the first type
doesn't work for you for files.
You can just try to put only this AddType php .html .htm to your htaccess, If this AddType application/x-httpd-php .html .htm doesn't work.
Don't know if it helps but... My example after hour of searching:
AddType application/x-httpd-php .php
LoadModule php5_module "c:/server/php5/php5apache2_2.dll"
ScriptAlias /_php/ "c:/server/php5/"
in httpd.conf
Without LoadModule and ScriptAlias it didn't process php at all and showed plaintext
Been stumped by this a lot before and what probably is happening, if none of the others worked, is your reading it as a file and not going through apache. Check your address bar and make sure it starts with localhost, your ip, 127.0.0.1, or your domain name if you've already set it up to direct to your server.
If you are trying to run very old PHP code, make sure you have
short_open_tag = On
in your php.ini
or, even better (because it's not recommended to use short open tags for new code anymore) to enable for specific virtual host only via:
php_value short_open_tag On
in httpd.conf / .htaccess file.
You might want to try adding this line to your .htaccess file:
AddHandler x-mapp-php6 .html .htm
simplify to 3 steps:
vim /etc/httpd/conf/httpd.conf
AddType application/x-httpd-php .html
service httpd restart
I am using GoDaddy dedicated server with Plesk. Here is what I have to use to get it to work:
AddHandler fcgid-script .htm
FCGIWrapper /var/www/cgi-bin/cgi_wrapper/cgi_wrapper .htm
For the actual path of the cgi_wrapper, refer to the file:
/var/www/vhosts/yourdomain.com/conf/last_httpd.include
or /etc/httpd/conf.d/php_cgi.conf
Adding this to .htaccess solved my problem, using PHP 5.5:
AddType application/x-httpd-php .html
PHP is running with SuPHP:
<FilesMatch "\.html$">
SetHandler application/x-httpd-php
</FilesMatch>
AddHandler application/x-httpd-ea-php56 .html .htm
AddType application/x-httpd-ea-php56 .html .htm
this worked for me!
if you want url for www.examle.com/page.php?id=123&lang=it in seo like this www.examle.com/it/1/2/3/pagina.html
add in .htaccess
<Files it>
SetHandler php-script
</Files>
<Files ru>
SetHandler php-script
</Files>
and when create files "it" "ru" in web http root directrory like this:
<?php
// www.examle.com/it
$lang="it";
include("urlrewrite.php");
?>
<?php
// www.examle.com/ru
$lang="ru";
include("urlrewrite.php");
?>
For PHP version 5.6.40 run PHP as "FRM application served by Apache" ( Plesk )
add this in .httaccess
<FilesMatch "\.html$">
SetHandler php-script
</FilesMatch>
it's work for me
Open "MultiPHP INI Editor" from the cpanel
then enable "allow_url_include"
then add the below lines to your .htaccess file:
<IfModule mod_mime.c>
AddType application/x-httpd-ea-php73 .html .php .htm
</IfModule>
Options +FollowSymlinks
Important: must replace the php ver with yours

problem with htaccess file and handlers?

i asked a question if i can execute html files as php files and i got those answers
AddType application/x-httpd-php5 .php .html
and another answer
AddHandler application/x-httpd-php .html .htm
and here is another one
RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html
and i got 1 problem
when i used to write any condition to add type it send me to download the page instead of run it
for example if i have a file index.html which have php code
after i create the .htaccess and write
RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html
then try to navigate the link it send me to download index.html instead of run it
AddType is used to assign a MIME type to a file suffix.
F.e. to override the MIME type of an PDF *sic
AddType text/plain .pdf
This will force the browser to load and show a PDF as plain text, because server is sending the text/plain MIMe type. But many applications handle files by content and not by suffix.
RemoveHandler
This is unnecessary, you don't want to remove anything from the standard configuration.
AddHandler handler-name .htm
This should do it, but it depends on your server configuration. You need the right "handler-name".
Standard handler-name for most Apache servers with PHP installed is
AddHandler application/x-httpd-php .html
AddHandler application/x-httpd-php .htm
but it could differ and it depends on your configuration. If you are using a shared or managed hosting without access to the Apache configuration file, you should ask your hoster.
I was using shared hosting with handler-names like
AddHandler php4-cgi .php .html
or
AddHandler php52-cgi .php .html
and another was using totally different way like
AddType x-mapp-php5 .php .php5 .htm .html
Otherwise have a look on your Apache configuration file. This page may be helpful to find the right section and to adapt.
Did you try:
AddHandler application/x-httpd-php5 .htm .html
?
Exactly the same problem, the basic code forces page download, but this:
AddHandler application/x-httpd-php5 .php .htm .html
...rectified the issue & worked perfectly.
if you are using fcgi none of the above will work ;
you need
<IfModule mod_fcgid.c>
<Files ~ (\.html)>
SetHandler fcgid-script
FCGIWrapper /var/www/cgi-bin/cgi_wrapper/cgi_wrapper .html
Options +ExecCGI
allow from all
</Files>

Server not parsing .html as PHP

I have the included code in my .htaccess file but the php code I am attempting to include is not working.
Options +Includes
AddType text/html .htm .html
AddHandler server-parsed .htm .html
AddType application/octet-stream .vcf
AddOutputFilterByType DEFLATE text/html text/htm text/plain text/css text/php text/javascript application/x-javascript
Try:
AddType application/x-httpd-php .html .htm
UPDATE 1
It may be PHP version specific. If you're using PHP5 try:
AddType application/x-httpd-php5 .html .htm
UPDATE 2
Try:
RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html
Or here's yet another alternative way to do this:
<FilesMatch "\.html$">
ForceType application/x-httpd-php
</FilesMatch>
On Apache 2.2.22 (Ubuntu) with Php 5 add these lines to /etc/apache2/mods-enabled/php5.conf
<FilesMatch ".+\.html$">
SetHandler application/x-httpd-php
</FilesMatch>
and restart apache
sudo service apache2 restart
For godaddy shared hosting (php-cgi):
From http://sagarnangare.com/parse-html-as-php-using-htaccess-file-on-godaddy/
AddHandler fcgid-script .html
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .html
That's the only one that worked for me.
If you are using Plesk Control Panel:
PHP is running as an Apache module:
<IfModule mod_php5.c>
AddHandler php5-script .php .html .htm
AddType text/html .php .html .htm
</IfModule>
PHP is running as a FastCGI application:
<IfModule mod_fcgid.c>
<Files ~ (\.html)>
SetHandler fcgid-script
FCGIWrapper /var/www/cgi-bin/cgi_wrapper/cgi_wrapper .html
Options +ExecCGI
allow from all
</Files>
</IfModule>
PHP is running as a CGI application:
<Files ~ (\.html)>
SetHandler None
AddHandler php-script .html
Options +ExecCGI
allow from all
</Files>
Then
/usr/local/psa/admin/sbin/httpdmng --reconfigure-all
http://kb.odin.com/en/115773
VERY IMPORTANT that you must replace the "php5" to your OWN exact PHP version in the:
AddHandler application/x-httpd-php5 .html .htm
AddType application/x-httpd-php5 .html .htm
Because I have tried everithing in every way from all over the web, but nothing worked until I found a "MultiPHP Manager" menupoint under my CPanel, and under this I found out that my exact PHP version/name/id (or whatever it is called) was "ea-php56", so my working code is:
AddHandler application/x-httpd-ea-php56 .html .htm
AddType application/x-httpd-ea-php56 .html .htm
I have browsed all day the forums, comments, but I haven't found this very important information anywhere, so maybe You also have to look up your exact PHP version if it is not working!
If your server is using PHP5 then use this:
AddHandler application/x-httpd-php5 .html .htm
If it's not PHP5 then use
AddHandler application/x-httpd-php .html .htm
It worked for me on CPanel hosting.
If you are using some other linux hosting try this:
<IfModule mod_mime.c>
AddType application/x-httpd-php .html .php .htm
</IfModule>
Options +FollowSymlinks
For Godaddy server it worked for me
Options +ExecCGI
AddHandler fcgid-script .html
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .html
BenG, did any solution ever work for you?
this may help -- i found this topic confusing, because either statement worked for me in my local dev environment
AddHandler application/x-httpd-php .html .htm
or
AddType application/x-httpd-php .html .htm
after reading the apache documentation on both directives, it seems that you want to use AddType when adding a mime type not yet handled by apache, and AddHandler when you want apache to handle a file differently than its default handling of that file type. i may be wrong, but that does seem to be what the manual is saying.
so if you want apache to handle .html and .htm as if they were .php files then you would use the directive :
AddHandler application/x-httpd-php .html .htm
the .htaccess file you mention above is doing a few things, so maybe you could first verify that it does indeed tell apache to handle .htm and .html files as if they are .php files; then move on to the other directives you want to use.
I was stumped for 2 hours until I looked into /etc/php/7.2/fpm/pool.d/www.conf and then uncommented the security setting to force php to only parse php and added .html so that the line now is security.limit_extensions = .php .php3 .php4 .php5 .php7 .html and then sudo service php7.2-fpm restart and doing the
<head>
</head>
<body>
This should show date here:
<?php echo date('l, F jS, Y'); ?>
</body>
and saved as test.html worked fine and displayed!
From http://support.lunarpages.com/knowledge_bases/article/321
How can I configure Apache to treat
.html files as PHP under suPHP? You
need to remove any previous entries
for handling .html files as PHP and
insert the following in your .htaccess
file: AddHandler x-httpd-php .html
.htm Or you can add this manually
using Cpanel -> Apache Handlers ->
New: Extension: .html .htm Handler:
x-httpd-php The newest cPanel servers
actually require the following
instead: AddHandler
application/x-httpd-php .html .htm or
AddType application/x-httpd-php .html
.htm Please try this if the first type
doesn't work for you for files.
You can just try to put only this AddType php .html .htm to your htaccess, If this AddType application/x-httpd-php .html .htm doesn't work.
Don't know if it helps but... My example after hour of searching:
AddType application/x-httpd-php .php
LoadModule php5_module "c:/server/php5/php5apache2_2.dll"
ScriptAlias /_php/ "c:/server/php5/"
in httpd.conf
Without LoadModule and ScriptAlias it didn't process php at all and showed plaintext
Been stumped by this a lot before and what probably is happening, if none of the others worked, is your reading it as a file and not going through apache. Check your address bar and make sure it starts with localhost, your ip, 127.0.0.1, or your domain name if you've already set it up to direct to your server.
If you are trying to run very old PHP code, make sure you have
short_open_tag = On
in your php.ini
or, even better (because it's not recommended to use short open tags for new code anymore) to enable for specific virtual host only via:
php_value short_open_tag On
in httpd.conf / .htaccess file.
You might want to try adding this line to your .htaccess file:
AddHandler x-mapp-php6 .html .htm
simplify to 3 steps:
vim /etc/httpd/conf/httpd.conf
AddType application/x-httpd-php .html
service httpd restart
I am using GoDaddy dedicated server with Plesk. Here is what I have to use to get it to work:
AddHandler fcgid-script .htm
FCGIWrapper /var/www/cgi-bin/cgi_wrapper/cgi_wrapper .htm
For the actual path of the cgi_wrapper, refer to the file:
/var/www/vhosts/yourdomain.com/conf/last_httpd.include
or /etc/httpd/conf.d/php_cgi.conf
Adding this to .htaccess solved my problem, using PHP 5.5:
AddType application/x-httpd-php .html
PHP is running with SuPHP:
<FilesMatch "\.html$">
SetHandler application/x-httpd-php
</FilesMatch>
AddHandler application/x-httpd-ea-php56 .html .htm
AddType application/x-httpd-ea-php56 .html .htm
this worked for me!
if you want url for www.examle.com/page.php?id=123&lang=it in seo like this www.examle.com/it/1/2/3/pagina.html
add in .htaccess
<Files it>
SetHandler php-script
</Files>
<Files ru>
SetHandler php-script
</Files>
and when create files "it" "ru" in web http root directrory like this:
<?php
// www.examle.com/it
$lang="it";
include("urlrewrite.php");
?>
<?php
// www.examle.com/ru
$lang="ru";
include("urlrewrite.php");
?>
For PHP version 5.6.40 run PHP as "FRM application served by Apache" ( Plesk )
add this in .httaccess
<FilesMatch "\.html$">
SetHandler php-script
</FilesMatch>
it's work for me
Open "MultiPHP INI Editor" from the cpanel
then enable "allow_url_include"
then add the below lines to your .htaccess file:
<IfModule mod_mime.c>
AddType application/x-httpd-ea-php73 .html .php .htm
</IfModule>
Options +FollowSymlinks
Important: must replace the php ver with yours

Categories