.htaccess 和 AddHandler php5-script .php 行有什么作用?
我使用新的网络托管服务商。我创建的每个域的 public_html 文件夹都是使用 .htaccess 自动生成的,其中包含以下行:
AddHandler php5-script .php
这是做什么的?
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:
AddHandler php5-script .php
What is this for?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这只是指示 PHP 通过将文件传递给 PHP5 解释器来处理以
.php
结尾的文件。如果没有此配置,Web 服务器可能会将文件作为原始 PHP 代码提供给最终用户的 Web 浏览器,而不是执行该代码。这增加了暴露数据库登录凭据或其他秘密的危险可能性。使用相同的机制,您可以配置 Web 服务器将除
.php
之外的其他扩展名的文件解析为 PHP 脚本,并将它们交给 PHP 解释器。例如,有时会通过使用.html
扩展名来命名 PHP 脚本来掩盖 PHP 脚本。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.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.它告诉 php 处理文件名中带有 .php 的任何文件,即使它不在末尾。名为 smile.php.gif 的文件将被解释为 php 文件,如果您要使用上传脚本,这会很糟糕。这是因为 Apache 允许以任意顺序排列多个扩展名,因此 gif.php.jpg 与 gif.jpg.php 相同。我听说选择处理程序的最佳方法是使用 FilesMatch。当然,如果您的网络主机的 httpd.conf 中有此内容,并且您无权访问 httpd.conf,则必须在使用 FilesMatch 之前使用 htaccess 将其“删除”。
It tells php to handle any file with .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.
答案是 htaccess 告诉网络服务器将
php
处理为php5-script
并执行它。The answer is that the htaccess tells the webserver to handle the
php
asphp5-script
and execute it.