解析HTML作为PHP [英] Parse HTML as PHP

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

问题描述

是否有任何安全/性能的考虑,如果我们设置Apache Web服务器配置Apache来处理的所有的HTML作为PHP?我是专门指的是:

 将AddType应用/ X的httpd  -  PHP的.php .php3 .php4的.html

我在哪里,我需要添加一些PHP逻辑放到一些HTML文件的情况;理想情况下,我没有要改变文件名如 page.html即可 page.php (保持网页排名等,为页html的)。

这是涉及到以下问题:的httpd AddType指令

编辑:
从下面的现有答案/评论,它看起来像社区建议要么使用重定向或仅针对特定的HTML文件。约束是,我重新设计现有的网站(400+ HTML页面;他们每个人都使用某种Dreamweaver模板的,在标题和来自不同的文件尾拉)。我希望能完全害羞远离Dreamweaver中移动到的东西非专有的。所以,我打倒两个选项:


  1. 使用服务器端包含(SSI)拉在页眉和页脚。这将导致我所有的HTML文件与SSI装饰。

  2. 撒上一些PHP代码片段,包括页眉和页脚。对于这个选择,我的有无的,以确保文件名保持不变。


解决方案

更​​多的文件服务器确定它需要通过PHP间preTER,更多的开销参与其中,但我认为这不用多说。如果您的网站没有与纯HTML的任何页面,那么你已经支付所有的性能损失,你可以支付可能 - 添加HTML到列表中是没有什么不同的在这种情况下不是简单地重命名所有这些文件有一个.php扩展名。

真正的性能损失会来,如果你的有普通的HTML页面 - 服务器会不必要地通过这些页面给PHP间pretation当没有必要。但即便如此,它不是戏剧性 - 将不再需要为这些HTML页面的PHP间preTER,所以它不会从确定不需要做任何事情做任何事情放在一边。这有一个代价,但它不是显著

现在,如果我们在这里谈论高容量,性能方面一点一滴,这不会是一个可行的解决方案。对于低到中量的网站,但是,性能损失会nill。

如果这是一次改变并且有受到影响,那么它可能是比较保守的使用 FilesMatch 指令文件的数量有限。

 < FilesMatch。^(file_one | file_two | file_three)\\ $ HTML>
  将AddType应用/ X的httpd - PHP的.html
< / FilesMatch>

Are there any security / performance concerns if we set the Apache web server to configure Apache to handle all HTML as PHP? I was specifically referring to:

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

I was in a situation where I needed to add some PHP logic into some HTML files; ideally, I didn't have to change the filename e.g. page.html to page.php (to keep the page rank, etc. for page.html).

This is related to the following question: httpd AddType directive

Edits: From the existing answers / comments below, it looks like the community suggests to either use redirects or only target specific HTML files. The constraint is that I am redesigning an existing site (400+ HTML pages; each of them uses some sort of Dreamweaver template that pulls in the header and footer from different files). I was hoping to completely shy away from Dreamweaver move into something non-proprietary. So, I am down with two options:

  1. Use Server Side Includes (SSI) to pull in the header and footer. This will result in all my HTML files to be decorated with SSI.
  2. Sprinkle some PHP snippet to include the header and footer. For this choice, I have to make sure the file name stays unchanged.

解决方案

The more files the server determines it needs to pass through the PHP interpreter, the more overhead involved, but I think this goes without saying. If your site does not have ANY pages with plain HTML, then you're already paying all the performance penalties that you could possibly pay - adding HTML to the list is no different in this case than simply renaming all the files to have a .php extension.

The real performance penalty would come if you do have plain HTML pages - the server will needlessly pass these pages to PHP for interpretation when none is necessary. But even then, it isn't dramatic - the PHP interpreter won't be needed for those HTML pages, so it won't do anything aside from determining that it doesn't need to do anything. This has a cost, but it isn't significant.

Now, if we're talking high-volume here, every little bit of performance matters and this would not be a practicable solution. For low- to mid-volume sites, however, the performance penalty would be nill.

If this is a one-time change and there are a limited number of files that are affected, then it may be more conservative to use a FilesMatch directive.

<FilesMatch "^(file_one|file_two|file_three)\.html$">
  AddType application/x-httpd-php .html
</FilesMatch>

这篇关于解析HTML作为PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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