A
A
Andrei2013-03-29 15:11:32
Nginx
Andrei, 2013-03-29 15:11:32

Remove floating slash in $uri try_files

Please help me correct the nginx config in the most correct way.
It is necessary to first check real files through try_files, then, for example, on request /page/ give the file /pages/page.html, and send all other requests to the handler.
The following code works for /page but fails as expected on /page/

location / { try_files $uri $uri/ /pages/$uri.html /script.php?$args; }

How to cut off the trailing slash in a request? Or it is necessary to do through rewrite?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Peretyatko, 2013-03-29
@this

I usually use try_files $uri $uri/ $uri/index.html @fetch;
Well, I save static files not /pages/page.html, but /pages/page/index.html.
If you want to do exactly as you wrote, then most likely you need to use rewrite ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question