为什么需要将Nginx中的$ args重定向到index.php? [英] Why do I need to redirect $args in nginx to index.php?

查看:338
本文介绍了为什么需要将Nginx中的$ args重定向到index.php?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

许多PHP框架建议将其添加到nginx中:

Many PHP frameworks suggest to add this to nginx :

location / {
    try_files $uri /index.php$is_args$args;
}

在所有HTTP请求上执行index.php.

to execute index.php on all HTTP requests.

为什么需要$is_args$args??我认为$args已经在HTTP GET请求中.那么,nginx为什么需要通过这种方式将它们传递给index.php?

Why do I need $is_args$args? I think the $args are already in the HTTP GET request. So why does nginx need to pass them that way to index.php?

推荐答案

这取决于谁写了index.php. nginx将大量参数发送到PHP,通常其中包括QUERY_STRING和REQUEST_URI.

It depends on who wrote index.php. A large number of parameters are sent to PHP from nginx, and usually QUERY_STRING and REQUEST_URI are among them.

如果程序员访问$_SERVER["QUERY_STRING"],他们将收到try_files语句中附加到/index.php末尾的任何内容.

If the programmer accesses $_SERVER["QUERY_STRING"] they will receive whatever was appended to the end of /index.php in the try_files statement.

如果程序员访问$_SERVER["REQUEST_URI"],他们将收到原始URI和原始查询字符串,并且在try_files语句中附加到/index.php末尾的任何内容都不会对此造成影响.

If the programmer accesses $_SERVER["REQUEST_URI"] they will receive the original URI together with the original query string, and anything appended to the end of /index.php in the try_files statement will not affect that.

我托管的两个应用程序(WordPress和MediaWiki)显然都使用了后者,因为我没有将$is_args$args附加到/index.php上,并且一切正常.

The two applications that I host (WordPress and MediaWiki) obviously use the latter, because I do not append $is_args$args to the /index.php and it all works fine.

但是另一个应用程序的行为可能有所不同.

But another application may behave differently.

这篇关于为什么需要将Nginx中的$ args重定向到index.php?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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