强制apache将html文件解析为php [英] Force apache to parse html files as php

查看:95
本文介绍了强制apache将html文件解析为php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望apache解析php代码的所有.html文件。我们的''真实''网页

服务器是从ICDsoft租用的(Linux上的Apache 5上的PHP 5),

他们的指令是将以下内容添加到.htaccess文件:

AddHandler应用程序/ x-httpd-php .html

....效果很好。


但是,我们的本地办公室服务器用于测试和查看我们的网站是在Windows XP专业版上使用PHP 4.4.4的Apache 2.0.55。我已经阅读了所有内容

我可以找到,并尝试将以下内容添加到httpd.conf文件中,

我能想到的每个组合:

AddHandler应用程序/ x-httpd-php .html

和/或:

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


但页面只是作为html发送而没有在

all解析php代码(是的,我确实在每次更改后重启Apache)。我在做什么

错了?


(这是httpd.conf之前包含的内容 - 注意它工作得很好

for .php files :)

ScriptAlias / php /" c:/ php /"

LoadModule php4_module" c:/php/php4apache2.dll" ;

AddType application / x-httpd-php .php

动作应用程序/ x-httpd-php" /php/php.exe"

PHPIniDir" C:/ php"

解决方案

Gary Hasler写道:


我希望apache解析PHP代码的所有.html文件。我们的''真实''网页

服务器是从ICDsoft租用的(Linux上的Apache 5上的PHP 5),

他们的指令是将以下内容添加到.htaccess文件:

AddHandler应用程序/ x-httpd-php .html

...效果很好。


然而,我们的用于测试和查看我们网站的本地办公室服务器是在Windows XP专业版上使用PHP 4.4.4的Apache 2.0.55。我已经阅读了所有内容

我可以找到,并尝试将以下内容添加到httpd.conf文件中,

我能想到的每个组合:

AddHandler应用程序/ x-httpd-php .html

和/或:

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


但页面只是作为html发送而没有在

all解析php代码(是的,我确实在每次更改后重启Apache)。我在做什么

错了?


(这是httpd.conf之前包含的内容 - 注意它工作得很好

for .php files :)

ScriptAlias / php /" c:/ php /"

LoadModule php4_module" c:/php/php4apache2.dll" ;

AddType application / x-httpd-php .php

动作应用程序/ x-httpd-php" /php/php.exe"

PHPIniDir" C:/ php"



只需在AddType行之后添加.html,就像这样:


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


它应该有效。其他人会告诉你,这是一个坏主意,因为它会导致甚至没有PHP的页面通过PHP

解析器,然后才会被发送到浏览器。但如果你需要

,那么无论如何......


我这样做:


..php .htm表示可能由PHP生成或包含PHP生成的任何页面

输出。如果你愿意,你甚至可以添加自己的东西 - 没关系。只是

不要过度使用mime类型。


其他任何东西应该被解析为html或者它们各自的mime类型。我用

个人结束静态页面(没有动态)与.html或.shtml


Norm


< blockquote> Norman Peelman写道:


>其他任何东西应该被解析为html或者它们各自的mime类型。

http://groups.google.co.uk/group/alt...strophe/topics


Norman Peelman写道:


>

Gary Hasler写道:


我想要apache来解析PHP代码的所有.html文件。我们的''真实''网页

服务器是从ICDsoft租用的(Linux上的Apache 5上的PHP 5),

他们的指令是将以下内容添加到.htaccess文件:

AddHandler应用程序/ x-httpd-php .html

...效果很好。


然而,我们的用于测试和查看我们网站的本地办公室服务器是在Windows XP专业版上使用PHP 4.4.4的Apache 2.0.55。我已经阅读了所有内容

我可以找到,并尝试将以下内容添加到httpd.conf文件中,

我能想到的每个组合:

AddHandler应用程序/ x-httpd-php .html

和/或:

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


但页面只是作为html发送而没有在

all解析php代码(是的,我确实在每次更改后重启Apache)。我在做什么

错了?


(这是httpd.conf之前包含的内容 - 注意它工作得很好

for .php files :)

ScriptAlias / php /" c:/ php /"

LoadModule php4_module" c:/php/php4apache2.dll" ;

AddType application / x-httpd-php .php

动作应用程序/ x-httpd-php" /php/php.exe"

PHPIniDir" C:/ php"



只需在AddType行上添加.html后添加.html如下:

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


它应该有效。其他人会告诉你,这是一个坏主意,因为它会导致甚至没有PHP的页面通过PHP

解析器,然后才会被发送到浏览器。但如果你需要

,那么无论如何......


我这样做:


.php .htm用于任何可能由PHP生成或包含PHP生成的页面

输出。如果你愿意,你甚至可以添加自己的东西 - 没关系。只是

不要过度使用mime类型。


其他任何东西应该被解析为html或者它们各自的mime类型。我用

个人结束静态页面(无动态)与.html或.shtml


Norm



谢谢Norm;

但我知道发生了什么(如果我发布了一个

问题,总是会发生!)..

我我们之前在httpd.conf中打开了SSI,我想它不能同时执行

吗?:


< Directory />

选项索引FollowSymLinks

选项+包含

AddType text / html .shtml


#--THESE线路必须被删除:

#AddOutputFilter包含.html

#AddHandler服务器解析.html

< /目录>


I want apache to parse all .html files for php code. Our ''real'' web
server is rented from ICDsoft ( php 5 on Apache on Linux whatever), and
their instruction is to add the following to the .htaccess file:
AddHandler application/x-httpd-php .html
....which works great.

However, our local in-office server for testing and viewing our sites is
Apache 2.0.55 with PHP 4.4.4 on Windows XP Pro. I have read everything
I can find, and have tried adding the following to the httpd.conf file,
in every combination I can think of:
AddHandler application/x-httpd-php .html
and / or:
AddType application/x-httpd-php .php .html

but the page just gets sent as html without the php code being parsed at
all (and yes, I do restart Apache after each change). What am I doing
wrong?

(Here''s what httpd.conf contained before--note that it works just fine
for .php files:)
ScriptAlias /php/ "c:/php/"
LoadModule php4_module "c:/php/php4apache2.dll"
AddType application/x-httpd-php .php
Action application/x-httpd-php "/php/php.exe"
PHPIniDir "C:/php"

解决方案

Gary Hasler wrote:

I want apache to parse all .html files for php code. Our ''real'' web
server is rented from ICDsoft ( php 5 on Apache on Linux whatever), and
their instruction is to add the following to the .htaccess file:
AddHandler application/x-httpd-php .html
...which works great.

However, our local in-office server for testing and viewing our sites is
Apache 2.0.55 with PHP 4.4.4 on Windows XP Pro. I have read everything
I can find, and have tried adding the following to the httpd.conf file,
in every combination I can think of:
AddHandler application/x-httpd-php .html
and / or:
AddType application/x-httpd-php .php .html

but the page just gets sent as html without the php code being parsed at
all (and yes, I do restart Apache after each change). What am I doing
wrong?

(Here''s what httpd.conf contained before--note that it works just fine
for .php files:)
ScriptAlias /php/ "c:/php/"
LoadModule php4_module "c:/php/php4apache2.dll"
AddType application/x-httpd-php .php
Action application/x-httpd-php "/php/php.exe"
PHPIniDir "C:/php"

Just add .html after .php on the AddType line like so:

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

and it should work. Others will tell you that that is a bad idea in that
it causes even pages that have no PHP in them to go through the PHP
parser before getting sent out to the browser. But if you have a need
for it then by all means...

I do:

..php .htm for any page that may be created by or contain PHP generated
output. You can even add your own if you want - doesn''t matter. Just
don''t over-ride a mime-type.

anything else should get parsed as html or it''s respective mime-type. I
personally end static pages (no dynamic) with either .html or .shtml

Norm


Norman Peelman wrote:

>anything else should get parsed as html or it''s respective mime-type.

http://groups.google.co.uk/group/alt...strophe/topics


Norman Peelman wrote:

>
Gary Hasler wrote:

I want apache to parse all .html files for php code. Our ''real'' web
server is rented from ICDsoft ( php 5 on Apache on Linux whatever), and
their instruction is to add the following to the .htaccess file:
AddHandler application/x-httpd-php .html
...which works great.

However, our local in-office server for testing and viewing our sites is
Apache 2.0.55 with PHP 4.4.4 on Windows XP Pro. I have read everything
I can find, and have tried adding the following to the httpd.conf file,
in every combination I can think of:
AddHandler application/x-httpd-php .html
and / or:
AddType application/x-httpd-php .php .html

but the page just gets sent as html without the php code being parsed at
all (and yes, I do restart Apache after each change). What am I doing
wrong?

(Here''s what httpd.conf contained before--note that it works just fine
for .php files:)
ScriptAlias /php/ "c:/php/"
LoadModule php4_module "c:/php/php4apache2.dll"
AddType application/x-httpd-php .php
Action application/x-httpd-php "/php/php.exe"
PHPIniDir "C:/php"


Just add .html after .php on the AddType line like so:

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

and it should work. Others will tell you that that is a bad idea in that
it causes even pages that have no PHP in them to go through the PHP
parser before getting sent out to the browser. But if you have a need
for it then by all means...

I do:

.php .htm for any page that may be created by or contain PHP generated
output. You can even add your own if you want - doesn''t matter. Just
don''t over-ride a mime-type.

anything else should get parsed as html or it''s respective mime-type. I
personally end static pages (no dynamic) with either .html or .shtml

Norm

Thanks Norm;
however I figured out what was happening (always happens if I post a
question!)..
I had SSI turned on earlier in the httpd.conf and I guess it can''t do
both?:

<Directory />
Options Indexes FollowSymLinks
Options +Includes
AddType text/html .shtml

# --THESE LINES HAD TO BE DELETED:
#AddOutputFilter INCLUDES .html
#AddHandler server-parsed .html
</Directory>


这篇关于强制apache将html文件解析为php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆