V2 recursive subdirectory matching

My v1 config had the following rewrite directive

rewrite app/(.*).php app/403.html

that would match any PHP file located under /app or any of its subdirectories.
In v2, this doesn’t work for subdirectories.

A quick solution is to hardcode subdirectories with wildcards, like this:

rewrite /app/*.php /app/403.html
rewrite /app/*/*.php /app/403.html
rewrite /app/*/*/*.php /app/403.html

But this doesn’t seem practical. Is there a regex I’m missing?

You’ll want to use a named matcher block with a path_regexp matcher:

@appPhp {
    path_regexp ^/app/(.*).php
}
rewrite @appPhp /app/403.html

This should do the trick!

Read about request matchers here:

2 Likes

Thanks Francis!

1 Like

This topic was automatically closed after 30 days. New replies are no longer allowed.