HTML through PHP parser

2019-09-07 02:26发布

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.

2条回答
你好瞎i
2楼-- · 2019-09-07 02:39

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.

查看更多
兄弟一词,经得起流年.
3楼-- · 2019-09-07 02:49

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
查看更多
登录 后发表回答