Sunday, December 9, 2012

[Web] Render html files as php files

Case:
You have an html page and you have no access to server side code. But, since you're hosted on a server that supports php, why not render htm/html file extension with phpengine, so you can write php server side code?

Problem:
Doing this is possible, but can be tricky, specially using third party hosting companies such as godadd.com.
First, you need to get them to enable the htaccess file that allows you to add web server rules. Then you need to use AddType to configure html mime types to be rendered as php.

Solution:
- Retrieve .htacces file from the ftp server
- Rename or delete the .htaccess file from the ftp server (overwriting the existing one may not work)
- Configure your file for ASCII format, and add these lines:
Options +ExecCGI
AddType application/x-httpd-php5-3 .htm .php
AddHandler x-httpd-php5-3 .htm .php



- Upload the .htaccess again, to the ftp server, and give it +777 permissions
- Use or create an html page with php code and watch it render

<html>
<head>
<title>
</title>
</head>
<body>
< ?php phpinfo(); ?>
</body>
</html>

http://support.godaddy.com/groups/web-hosting/forum/topic/htaccess-to-handle-html-as-php/

No comments:

Post a Comment