Custom php extension not being parsed

2019-09-01 14:44发布

I wanted to change the .php extension to .foo, to hide it for visitors. My webserver has cPanel installed, so I logged in and clicked on "MIME Types", and entered the following:

MIME Type: application/x-httpd-php
Extension: foo

The problem is that it's not being parsed as PHP, but instead is downloaded (when you click the link, a file containing all the code of that file is being downloaded)

How would I solve this?

2条回答
家丑人穷心不美
2楼-- · 2019-09-01 14:47

If you have the necessary AllowOverride permissions to use .htaccess, try

AddHandler application/x-httpd-php5 .php .foo

For some reason our CentOS server needs x-httpd-php5, where as our WAMP internal server just uses x-httpd-php like you have (and -php5 will not work)

I have a CPanel based website and we used the above rule to set .html to be parsed as php, didn't even bother with the CPanel Mime settings... but there are other ways to determine if a server is running PHP so you're not really hiding that you use PHP from anyone who knows what they are doing

查看更多
Luminary・发光体
3楼-- · 2019-09-01 15:05

Add in httpd.conf or vhost.conf

<IfModule mime_module>
    AddType application/x-httpd-php .foo
</IfModule>

But best way to solve you problem is in using mod_rewrite

查看更多
登录 后发表回答