I have www.example.com/test and i want to write a condition if requested url is not equal to /test do a rewrite or redirect to www.example.com. The closest i can get is a code below but when i want to use www.example.com/test without / at the end it redirects me to www.example.com but when i type www.example.com/test/ it works.
location /
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param HTTPS on;
if ($request_uri !~ ^/test/(.*)$)
{return 301 $scheme://www.example.com;}
try_files $uri $uri/ /index.php$is_args$args;
}