Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question
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

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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