34

I know about the HttpRewriteModule, but I don't really know how to handle regex and I would need to redirect all URLs within a certain directory to another, specifically

example.com/component/tag/whatever

to

example.com/tag/whatever

Could some one tell me how to do this in Nginx?

57

Do you mean something like:

rewrite ^/component(.*)$ $1 last;
6
  • I think this will do it, thank you so much. I'm awful at regular expressions; I will have to try to learn them... – javipas Aug 18 '11 at 12:05
  • regex101.com/r/qJ5gU1/1 has explanation on the right side – Jon Mar 25 '15 at 11:13
  • 10
    You may need to replace last by break. (Last will try to resolve other locations after the rewrite). – Thomas Decaux Apr 11 '15 at 9:57
  • 5
    It only worked for me with break and not with last. – Guillaume Jun 20 '17 at 9:38
  • @ThomasDecaux what is the difference between break and last – Mothirajha Dec 4 '17 at 13:37

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.