I would like to create a location rule for two alias to one location.
This is the rule used for one location:
location ~ ^/images/(.*)$ { alias /var/www2/images/$1; }
What I would like to do is define two alias in location. So for example, I can visit http://domain.com/styles/file.css and http://domain.com/css/file.css and it would go to one alias which is /var/www2/styles/
I've tried something like this, but it did not work for me.
location ~ ^/(styles|css)(.*)$ { alias /var/www2/styles/$1; }
But the again, I don't know regex much.
Try:
location ~ ^/(?:styles|css)/(.*)$ { alias /var/www2/styles/$1; }
Or
location ~ ^/(styles|css)/(.*)$ { alias /var/www2/styles/$2; }
$1
refers to the first capturing group (...)
. When you added another group it referred to that one instead. You can use a non-capturing group (?:...)
instead, or refer to the second capturing group $2
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With