We switched over to the NGINX web server about six months ago from Apache. It has taken a while to get a handle on redirects and wildcards.

Here is a simple 301 wildcard domain redirect:

Now what happens if you have some ads out there with query string parameters like: http://old.domain-name.com/ad-landing-page?tracker=7879790870987

Those will redirect but lose NGINX’s $query_string value on the destination. Here is a simple workaround using a if $query_string:

What if you need to direct a specific folder path to a new domain with query strings and a wild card? Here is the kitchen sink version:

If the redirect is redirecting to the same domain you can use alias instead of return 301.

There you go. NGINX pretty much has the same amount of granularity when performing redirects that apache has.