I am writing some PHP code in my .htm and .html pages but it’s not executing the code.
I must strictly not have to change the page extension.
I have added this handler to the .htaccess
page
AddHandler application/x-httpd-php74 .php .htm
AddHandler application/x-httpd-php74 .php .html
My server PHP version is PHP 7.4
What I am missing, how to use PHP code in .htm and .htm pages?
I am doing this on siteguard hosting
so if any server configuration I may missing?
4
Answers
Add the following to your .htaccess
PHP able to work with CLI or .php script files otherwise doesn’t work. Because before from run PHP need compile.
You can use .htaccess abilities instead write code in HTML files. Just like the following code sample.
Creating dynamic URLs in htaccess
Here Moshe Gross’s method works!
this is only for test purpose:
i am tryin in xampp:
.htaccess
index.html
when i access http://localhost/testhtmlphp/ i got this result:
re: if i press F5 (refresh page) the timer change!
Sometimes the .htaccess file doesn’t work on my machine. Try putting it in the virtual host configuration file (/etc/apache2/sites-enabled/[file name].conf)
Tested on Debian 11 64-bit PHP 7.4, Apache 2.4.53
I don’t know if your hosting will allow that modifications. It probably will work in the .htaccess file.
Hopefully it helps!
Credit to Moshe Gross and Constantin