I've regularily embed standard HTML source within my PHP code by inserting it out of the <?PHP ?> tags. But I'd prefer to work in the opposite direction; that being construct my HTML files BUT occasionally embed my PHP code within the HTML file instead (that has the HTML extension). When I do this, however, from an Apache or IIS box, only the HTML is renderred and the PHP code is ignored. It seems the PHP code is only renderred/processed whenever the source file is a .PHP file.
Why do I want to do this? I prefer to author HTML source and distribute to others. Also, it's the HTLM pages I want to be found from popular search engines and not my files with the .PHP extension. Especially since the output they generate is dynamically created.
Some questions....
1. Is what I'm asking for above possible?
2. If not, are there any workarounds to accomplish what I'm attempting to do?
Thanks for your help to this "newbie" question.
Thanks
TechLinks (PHP link driven site)
http://www.techlinks.com
PHP without PHP Extension
Moderator: General Moderators
Yes it's possible, using Apache ".htaccess":
where ex is the file extension.
It's not recommended to parse all .html/.htm files as PHP.
Code: Select all
AddType application/x-httpd-php exIt's not recommended to parse all .html/.htm files as PHP.
This is very helpful. Thank you very much. Would it be good practice if I select just a "few" files to be parsed? For instance, I'm particularly interested in all the "index.html" files ONLY in all my directories. For instance:
http://www.techlinks.com/careers/index.html
http://www.techlinks.com/downloads/index.html
http://www.techlinks.com/services/index.html
If so, how would you modify the .htaccess file you mentioned in above to support this? Thanks again. In the meantime, I'm combing through the Apache online docs to figure this out. But if it's off the tip of your fingers, would you please share it with me? Thanks.
LBJ
http://www.techlinks.com/careers/index.html
http://www.techlinks.com/downloads/index.html
http://www.techlinks.com/services/index.html
If so, how would you modify the .htaccess file you mentioned in above to support this? Thanks again. In the meantime, I'm combing through the Apache online docs to figure this out. But if it's off the tip of your fingers, would you please share it with me? Thanks.
LBJ