-e vs -f and -d

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

-e vs -f and -d

ashuai
Hi,

Considering that I don't have symbolic links why do these configs work
differently ?

===config one===
if (!-f $request_filename) {
    rewrite ^/(.*)$ /init.php;
}
if (!-d $request_filename) {
    rewrite ^/(.*)$ /init.php;
}
===config one===

This one above works, rewrite happens.

Being changed to this it stops working, all other lines left intact:
===config two===
if (!-e $request_filename) {
    rewrite ^/(.*)$ /init.php;
}
===config two===

This is inside the location / {}.

Thanks.

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,277731,277731#msg-277731

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: -e vs -f and -d

Maxim Dounin
Hello!

On Mon, Dec 11, 2017 at 09:51:51AM -0500, drook wrote:

> Hi,
>
> Considering that I don't have symbolic links why do these configs work
> differently ?
>
> ===config one===
> if (!-f $request_filename) {
>     rewrite ^/(.*)$ /init.php;
> }
> if (!-d $request_filename) {
>     rewrite ^/(.*)$ /init.php;
> }
> ===config one===
>
> This one above works, rewrite happens.

This will rewrite all requests, since you have two independant
cases when a rewrite happens:

- rewrite if the requested resource is not a file;
- rewrite if the requested resource is not a directory;

Since no resource can be a file and a directory at the same time,
rewrite always happens.  That is, this configuration will rewrite
anything, including requests to existing files and directories.

> Being changed to this it stops working, all other lines left intact:
> ===config two===
> if (!-e $request_filename) {
>     rewrite ^/(.*)$ /init.php;
> }
> ===config two===

This will not rewrite resources which are either a file, or a
directory.  Everything else will be rewritten.  That is, this
configuration will not rewrite requests to existing files and
directories.

See here for more information on rewrite module directives and
their execution:

http://nginx.org/en/docs/http/ngx_http_rewrite_module.html

In particular, "rewrite_log on;" might be helpful if you want to
better understand what happens in your configuration.

--
Maxim Dounin
http://mdounin.ru/
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx