如何将PHP文件保存为的.php或.html扩展? [英] How to save php file as .php or .html extension?

查看:135
本文介绍了如何将PHP文件保存为的.php或.html扩展?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我们的PHP文件的.php,我们可以保存PHP文件为html的,因为在一些网站,我看到的网页与PHP扩展,我们为什么不能让PHP文件的扩展名为.html

why we have php file as .php , can we save php file as .html,because at some sites,I seen webpages with .php extension,why can't we have .html extension of php file.

是否影响对PHP的服务器引擎的PHP文件的执行。如果我们把它作为.html文件,里面有PHP的code里面。

Does it effect the execution of php file on php server engine. if we have it as .html file,which has php code inside it.

推荐答案

如果你真的想为你的PHP code与.html文件,是可以做到的。

If you really want to serve your PHP code with .html files, it can be done.

您的Web服务器配置通过查看扩展检测文件类型。默认情况下,将通过PHP跨preTER路线.php文件和.html文件将被直接提供给最终用户。您可以通过配置服务器的配置文件,或者对个人web目录本地.htaccess文件此行为。见@如何做到这一点kjy112的答案。

Your web server is configured to detect the file type by looking at the extension. By default it will route .php files through the PHP interpreter, and .html files will be served directly to the end user. You can configure this behaviour via the server's config file, or the local .htaccess file for the individual web directory. See @kjy112's answer for how to do this.

现在的问题是为什么呢?它是重要的是你要做到这一点,或者是你想作为一个精密只是一些。问问你自己:你会不会最终用户关心吗?甚至注意到了吗?

The question is why? Is it important for you to do this, or is it just something you want as a nicety. Ask yourself: Will your end-user care? or even notice?

浏览器配置这种方式默认的原因是,没有任何PHP code纯HTML文件可以提供给用户,而无需通过由PHP跨$ P正在处理的开销$ PTER。通过改变配置,所有的HTML文件将PTED为PHP即使他们实际上并不包含任何PHP code除$ P $,所以你可以添加额外的处理负载到您的服务器。当然,如果所有的文件有PHP code一些元素,你会反正想这种行为,因此这显然不会担心你。

The reason the browser is configured this way by default is so that plain HTML files that don't have any PHP code can be served to the user without going through the overhead of being processed by the PHP interpreter. By changing the configuration, all your HTML files will be interpreted as PHP even if they don't actually contain any PHP code, so you'll be adding extra processing load to your server. Of course, if all your files have some element of PHP code, you're going to want this behaviour anyway, so this obviously wouldn't worry you.

因此​​,它可以做到的。但也有可能是你更好的解决方案:

So it can be done. But there may be a better solution for you:

目前的趋势,搜索引擎优化(搜索引擎优化)就是要在URL中完全去掉文件扩展名。如果你看一下网址这个问题,你会发现它有一个十分生动的网址,并没有扩展名。如果你想遵循最佳实践目前的趋势,你可能要考虑去沿着这条路吧。

The current trend for SEO (search engine optimisation) is to get rid of file extensions in the URL entirely. If you look at the URL for this question, you'll see that it has a very descriptive URL, and without an extension. If you want to follow current trends of best-practice, you may want to consider going down this route instead.

这是通过使用的mod_rewrite 。 URL的描述部分完全是任意的:如果你改变它,该网页将仍然正确加载。的重要部分是描述前的ID号码;的描述仅仅是那里给页面与它的升压真实谷歌排名。所涉及的技术的全面讨论这一问题的范围之内,但也有很多资源,围绕这将帮助你(尝试搜索了mod_rewrite这里本网站下手)。

This is done using mod_rewrite. The descriptive part of the URL is completely arbitrary: if you change it, the page will still load correctly. The important part is the ID number before the description; the description is simply there to give the page a boost with it's Google ranking. A full discussion of the techniques involved is outside the scope of this question, but there are plenty of resources around that will help you (try searching for mod_rewrite right here on this site to start with).

提示:所有的特定服务器配置的意见,我在这里给适用于Apache Web服务器。如果您使用的是IIS或一些其他的服务器产品,您可能需要相应地调整它。

这篇关于如何将PHP文件保存为的.php或.html扩展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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