HTML through PHP parser

穿精又带淫゛_ 提交于 2019-12-12 03:19:43

问题


I'm trying to hide the fact I'm using PHP on one of my site pages and I'm wanting to run it through the PHP parser (just that page not them all) so I can call it filename.html as usual. I have tried a few Apache directives I found online and have a few in my .htaccess file (hotlinks and for a 404 page).

When i use one of the scripts (in my .htacess) for the PHP purpose, the page wants to be saved/downloaded (like a vcard does) and a box shows - with no page to view. Can anyone please help. I'm new to PHP but believe a module might be needed or that it could be to do with the config of my server.


回答1:


You should leave the page with a .php extension and have Apache handle the file as a normal PHP file. Then use a RewriteRule in your htaccess settings to hide the php file as follows:

RewriteEngine on
RewriteRule ^yourfile\.html$ yourfile.php



回答2:


There is no real need to hide the fact that you are using PHP, but if you really want to parse PHP in html files you need to edit your Apache httpd.conf file. Open it up in a text editor and find a group of lines that looks like this:-

AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php

(Yours may be slightly different)

Then add

AddType text/html .html

restart Apache and php in html files will be parsed.



来源:https://stackoverflow.com/questions/9700916/html-through-php-parser

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!