Nginx subpage location directive with error page

2020-02-14 nginx redirect location directive

we use a typo3 CMS and need to redirect two subpages /en /de to different error pages. I've come up with this:

location ~ ^/de/ {
    error_page 404 https://www.example.com/de/error-404/;
    error_page 403 https://www.example.com/de/error-403/;
}
location ~ ^/en/ {
    error_page 404 https://www.example.com/en/error-404/;
    error_page 403 https://www.example.com/en/error-403/;
}

but this will redirect it in a loop.

Anyway i can achieve this within NGINX?

Answers

Seems like i am too stupid for regex:

location ^/de/.+ {
    error_page 404 https://www.example.com/de/error-404/;
    error_page 403 https://www.example.com/de/error-403/;
}

works fine.

Related