简体   繁体   中英

htaccess - parsing php into html

I recently played with a .htaccess file to make one server to parse PHP files. Yesterday I uploaded the same .htaccess file and tried to test a PHP file. But something went wrong: visiting my page the browser offers to download the the html page rather then viewing the page!

On the server the filenames end in .html .

I added the following to my .htaccess file:

AddType application/x-httpd-php .html

I tried to find the htaccess file, but once uploaded it just disappears from the root dir. I tried to upload other scripts I've found browsing. I even tried to search for some problem on a hosting forum. Nothing helped. Please help!

Try this

AddType application/x-httpd-php .php .htm .html

OR

AddHandler application/x-httpd-php .php .htm .html

And remove other overriding handlers for application/x-httpd-php after above code.

Right, firstly things first, what host do you use?

Also what ftp client you are using? Some by default won't display files starting with . such as .htaccess and .htpasswd , that's why it may appear that you didn't upload it. Also it might be that you don't have the rights to upload in the very root directory, try to go one directory up.

Also from my experience, hosts won't allow you to modify headers via .htaccess this way, because the allowoverride directive is off; instead have a look at url rewrites (via mod_rewrite ), which allow you to do the same thing without modifying headers.

Your rewrite .htaccess file might look something like:

RewriteEngine On
RewriteBase /
RewriteRule ^(\w+)\.html$ $1.php [NC] 

(Not tested though) Using a rewrite will also mean that your files will in fact maintain the php extension, however they will be access via urls that include .html extension.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM