简体   繁体   English

htaccess - 将php解析为html

[英]htaccess - parsing php into html

I recently played with a .htaccess file to make one server to parse PHP files. 我最近使用.htaccess文件来制作一个服务器来解析PHP文件。 Yesterday I uploaded the same .htaccess file and tried to test a PHP file. 昨天我上传了相同的.htaccess文件并尝试测试PHP文件。 But something went wrong: visiting my page the browser offers to download the the html page rather then viewing the page! 但出了点问题:访问我的页面浏览器提供下载html页面而不是查看页面!

On the server the filenames end in .html . 在服务器上,文件名以.html结尾。

I added the following to my .htaccess file: 我将以下内容添加到我的.htaccess文件中:

AddType application/x-httpd-php .html

I tried to find the htaccess file, but once uploaded it just disappears from the root dir. 我试图找到htaccess文件,但一旦上传它就会从根目录中消失。 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. 并在上面的代码之后删除application/x-httpd-php其他重写处理application/x-httpd-php

Right, firstly things first, what host do you use? 对,首先是事情,你使用什么主机?

Also what ftp client you are using? 还有你正在使用的ftp客户端? 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. 例如.htaccess.htpasswd ,这就是为什么看起来你没有上传它。 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; 另外根据我的经验,主机不允许你通过这种方式通过.htaccess修改标题,因为allowoverride指令是关闭的; instead have a look at url rewrites (via mod_rewrite ), which allow you to do the same thing without modifying headers. 而是看看url重写(通过mod_rewrite ),它允许你在不修改标题的情况下做同样的事情。

Your rewrite .htaccess file might look something like: 您的重写.htaccess文件可能类似于:

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. (虽然未经过测试)使用重写也意味着您的文件实际上将维护php扩展,但是它们将通过包含.html扩展名的URL访问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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