location /movies {
  return 301 nice.com
location /foo {
  rewrite /foo/(.*) /$1;

I am accessing http://localhost/foo/movies. What happens is url gets changed to http://localhost/foo/nice.com. I want to know why because Here is what I think.

when accessing http://localhost/foo/movies, it gets rewritten as http://localhost/movies internally. then it starts processing from top to bottom and finds /movies endpoint. when It finds, it has to redirect to nice.com website. but only last part changes.


Your return statement is probably being interpreted as a path relative to the original URI.

You need to use URL syntax to specify an external site, for example:

return 301 https://example.com/;

See this document for details.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.