NGINX Redirection/Return with MultiSite

I have an NGINX server running WordPress MultiSite (sub-directories). Due to the way some sites were originally created, I need to create a redirect (or more correctly in NGINX terminology, a “return”:wink: on requests to a sub-domain (we’ll call it to goto (which is managed as a sub-site in my WP multi-site).

From what I’ve read, I have two basic choices – hard-code it in the nginx config or use some regular expressions to translate the redirect. Either way, I can’t seem to get it it to work. NGINX responds to but it always redirects to the main sub-site in the WP site. Any ideas? Here is a copy of the relevant NGINX config. We are running SSL for both the front and back end.

I’d appreciate any other feedback you see on the config below. If you think it would be helpful to see more configuration, let me know, but I think I have the parts that matter.

server {


return 301$request_uri; #would like this to be dynamic


map $uri $blogname{

~^(?P<blogpath>/[^/]+/)files/(.*) $blogpath ;


server {

listen 80;

return 301 https://$host$request_uri;


server {

listen 443 ssl;


root /var/www/wwwroot_domain;

index index.php;

  • Aaron
    • CTO

    Your example looks correct. Is the redirect working then it gets redirected back? That would be the case if you didn’t change your configs and db tables to work as a subdir install.

    You could probably make it dynamic with something like:

    server_name ~^(?P<sub>.+)$;
    return 301$sub$request_uri;


Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.