T
T
Tyoma Makeev2015-12-02 00:09:56
Nginx
Tyoma Makeev, 2015-12-02 00:09:56

How to setup try_files in nginx?

How to make in nginx so that the file domain.com/12345.html opens on request /12345 , and /12345.html , and /12345/, and /12345.html/ ? Something from this either works out, or not, but all together so that it doesn’t work out at all.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Softer, 2015-12-02
@Softer

Probably something like this :)

location ~ ^/[0-9]+
{
rewrite ^/([0-9]+)[^0-9]*$ /$1.html;
}

I
Igor Deyashkin, 2015-12-02
@Lobotomist

Something like that:

location ~ ^(/\d+)(\.html)?\/?$ {
    try_files $1.html =404
}

The whole point is in the regexp: Beginning of the string - a few digits - 0 or 1 occurrences of ".html" - 0 or 1 occurrences of "/" - end of the string. .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question