带有行 AddHandler php5-script .php 的 .htaccess 有什么作用?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7856825/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
what does .htaccess with line AddHandler php5-script .php do?
提问by IberoMedia
I am with new web host. The public_html folder of each domain I create is auto generated with an .htaccess that has the following line:
我与新的网络主机。我创建的每个域的 public_html 文件夹都是使用具有以下行的 .htaccess 自动生成的:
AddHandler php5-script .php
What is this for?
这个是来做什么的?
回答by Michael Berkowski
This just instructs PHP to handle files ending in .php
by passing them to the PHP5 interpreter. Without this configuration in place, the web server may serve the files to the end-user's web browser as raw PHP code, rather than executing the code. That raises the dangerous possibility of exposing database login credentials or, or other secrets.
这只是指示 PHP.php
通过将它们传递给 PHP5 解释器来处理以 结尾的文件。如果没有这种配置,Web 服务器可能会将文件作为原始 PHP 代码提供给最终用户的 Web 浏览器,而不是执行代码。这增加了暴露数据库登录凭据或其他秘密的危险可能性。
Using the same mechanism, you could configure the web server to parse files with other extensions besides .php
as PHP scripts and hand them to the PHP interpreter. This is occasionally done to mask PHP scripts by naming them with .html
extensions, for example.
使用相同的机制,您可以配置 Web 服务器以解析除.php
PHP 脚本之外的其他扩展名的文件,并将它们交给 PHP 解释器。例如,有时这样做是为了通过使用.html
扩展名命名 PHP 脚本来屏蔽 PHP 脚本。
# Interpret both .php & .html as PHP:
AddHandler php5-script .php .html
回答by joseph
It tells php to handle any filewith .php in the filename, even if it's not at the end. A file named smile.php.gif will be interpereted as a php file, which is bad if you are going to be using an upload script. This is because Apache allows multiple extensions in any order, so gif.php.jpg is the same as gif.jpg.php. I have heard the best way to select the handler is with FilesMatch. Of course if your web host has this in their httpd.conf you would have to 'remove' it using your htaccess before using the FilesMatch if you don't have access to httpd.conf.
它告诉 php 处理文件名中带有 .php 的任何文件,即使它不在末尾。一个名为smile.php.gif 的文件将被解释为一个php 文件,如果您要使用上传脚本,这会很糟糕。这是因为 Apache 允许以任意顺序进行多个扩展,因此 gif.php.jpg 与 gif.jpg.php 相同。我听说选择处理程序的最佳方法是使用 FilesMatch。当然,如果您的网络主机在他们的 httpd.conf 中有这个,如果您无权访问 httpd.conf,则在使用 FilesMatch 之前,您必须使用您的 htaccess 来“删除”它。