I'm trying to redirect domain1.com/blog/$ to domain2.com/$. How do I edit this to strip the /blog from the redirect?

location /blog {
    rewrite ^/(.*) http://domain2.com/$1 break;

It now redirects domain1.com/blog/blabla to domain2.com/blog/blabla (so blog is still there).. Thanks in advance!!

  • 2
    You may try: rewrite ^/blog/(.*) http://domain2.com/$1 break; (in which case, you might also be able to get rid of the location block). – cyberx86 Jun 10 '12 at 22:57
  • It works!!! :) Thanks!! I can't set your reply as the right one because you added a comment instead of a reply (I think.. I'm rather new here).. :( – MultiformeIngegno Jun 10 '12 at 23:16
  • You cannot accept a comment - and respondents shouldn't post answers as comments - it's a bad habit of mine (usually when I don't have a chance to verify my answer). Posted as an answer so you can close out the question. – cyberx86 Jun 11 '12 at 0:21

You want the regex part of your rewrite to match against ^/blog/ and capture everything following it:

rewrite ^/blog/(.*) http://domain2.com/$1 break;

Using such an approach, you may also be able to get rid of the location block.

| improve this answer | |

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.