简体   繁体   中英

Why do I need to redirect $args in nginx to index.php?

Many PHP frameworks suggest to add this to nginx :

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

to execute index.php on all HTTP requests.

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?

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.

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM