3

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!!

3
  • 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, 2012 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).. :( Jun 10, 2012 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, 2012 at 0:21

1 Answer 1

2

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .