mac
mac

Reputation: 858

Nginx url domain redirect

With nginx, I would like to configure a redirect between two domains like this:

domainA.com/<anypath> to domainB.com/redirect/<anypath>

My code right now:

server {
    listen 80;
    server_name .domainA.org(.*)$;
    rewrite ^ http://domainB.org/redirect$1?;
}

The redirect from domainA to domainB works, but it doesn't include /redirect in the new path. Any help is appreciated! thanks!

Upvotes: 0

Views: 47

Answers (1)

Synchro
Synchro

Reputation: 37710

Nginx has some built-in functionality to handle this for you. Try this:

server {
    listen 80;
    server_name domainA.org;
    return 301 http://domainB.org/redirect$request_uri;
}

Upvotes: 2

Related Questions