'Nginx Location Passing Issue

I'd like to use a nginx proxy to pass certain directorys on my webserver to another directory.

i want example.com/somedirectory/* to send it back to example.com/somedirectory/

How would I do that?

I've tried

location /somedirectory/* {

    return 301 https://example.com/somedirectory;
}

But this doesn't work.

I also want to avoid having a constant redirect loop when I open example.com/somedirectory.



Solution 1:[1]

I've managed to do this using regex:

location ~^/somedirectory/(.*)$ {
    return 301 https://example.com/somedirectory;
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Halsi