Jun 11, 2012
tom

Nginx redirect: folder to external domain

Question

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

Answer

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.

Answered by cyberx86

Related posts:

  1. Nginx redirect one domain to another
  2. nginx folder redirect
  3. Redirect domain’s content to another domain
  4. How do I redirect multiple domains to a single domain in lighttpd
  5. Nginx: Rewrite from base domain to a sub directory

Leave a comment