I want redirect
https://dev.abc.com/ to https://uat.abc.com/
https://dev.abc.com/first to https://uat.abc.com/first
https://dev.abc.com/second to https://uat.abc.com/
https://dev.abc.com/third/ to https://dev.abc.com/third/ (Point the same)
I have tried with following config and achieved first three. But last one also redirecting to uat. Can anyone help me in this situation.
server {
listen 80;
server_name dev.abc.com;
root /var/www/
location ~* ^/first{
return 301 https://uat.abc.com$request_uri;
}
location ~* ^/second{
return 301 https://uat.abc.com;
}
location ~* ^/{
return 301 https://uat.abc.com$request_uri;
}
Can anyone help me on this configuration?
location ~* ^/
matches any URI that begins with /
- which is any URI that hasn't already matched an earlier regular expression location rule.
To match only the URI /
and nothing else, use the $
operator:
location ~* ^/$ { ... }
Or even better, and exact match location block:
location = / { ... }
See this document for more.
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