0

I'm trying to create a rewrite with nginx that will change the displayed URL without actually redirecting to it. EG: http://example.com/item/rest-of-path would become http://example.com/folder/rest-of-path. I've been working with different variations of this code with in my nginx.conf:

location ~ /example {
   rewrite ^/example/(.*) /folder/$1 last;
}

but that doesn't seem to be doing the trick. Any ideas where I'm going wrong here? I'll admit I'm still pretty new to server-side rewrites in general.

2 Answers 2

0

Try this:

location ~ /example {
   rewrite ^/example/(.*) /folder/$1 break;
}

use break.

1
  • This won't "change the displayed URL without actually redirecting to it.".
    – mrgoos
    Aug 31, 2019 at 21:04
-1

Try this. It isn't necessary to place it under the location block, and don't forget to reload nginx.

rewrite     ^/example/(.+)$     /folder/$1 last;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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