2011-08-19 41 views
1

我问一个问题,如果我可以执行的HTML文件,PHP文件和我得到这些问题的答案htaccess文件和处理程序的问题?

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

和另一个答案

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

这里有另外一个

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

和我得到1个问题 当我用写任何条件添加类型它发送给我下载页面而不是运行它 例如,如果我有有PHP代码 一个index.html文件后,我创建的.htaccess和写

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

然后尝试导航链接发给我的index.html,而不是下载运行它

+0

原题:http://stackoverflow.com/questions/7123560/small-problem-with-htaccess-file –

+0

[使用.htaccess将所有.html页面作为.php文件运行?](https://stackoverflow.com/questions/4687208/using-htaccess-to-make-all-html-pages-to -run-AS-PHP文件) – kenorb

回答

3

AddType用于将MIME类型分配给文件后缀。

F.e.覆盖MIME类型的PDF * SIC

AddType text/plain .pdf 

这将迫使浏览器加载和显示PDF为纯文本的,因为服务器发送纯文本/ MIME类型。但许多应用程序按内容处理文件,而不是后缀。

RemoveHandler 

这是不必要的,你不想从标准配置中删除任何东西。

AddHandler handler-name .htm 

这应该这样做,但它取决于您的服务器配置。你需要正确的“处理程序名称”。

标准处理名与PHP安装Apache的大多数服务器是

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

,但它可能有所不同,这取决于您的配置。如果您使用的共享或托管主机无法访问Apache配置文件,则应询问您的主机。

我使用共享与处理程序,名称托管样

AddHandler php4-cgi .php .html 

or 

AddHandler php52-cgi .php .html 

and another was using totally different way like 

AddType x-mapp-php5 .php .php5 .htm .html 

否则会对你的Apache配置文件看看。这page可能会有助于找到正确的部分和适应。

1

你尝试:

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

0

完全相同的问题,基本代码势力页面下载,但这:

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

...纠正问题&完美。

0

如果您正在使用fcgi没有以上会工作,所以你需要:

<IfModule mod_fcgid.c> 
<Files ~ (\.html)> 
    SetHandler fcgid-script 
    FCGIWrapper /var/www/cgi-bin/cgi_wrapper/cgi_wrapper .html 
    Options +ExecCGI 
    allow from all 
</Files> 
</IfModule>