Special type of nginx redirect: redirect only if $request_uri is empty I need a special type of redirect for a Drupal 6 website. I'm thinking that the best place to do this is in an nginx config file, but please correct me if I'm wrong. I know I can do it in a template file/module by checking $_GET['q'] and then using drupal_goto(), but I don't want to load the full bootstrap only to do a redirect.

Basically, I need to redirect www.domain.com and domain.com to subdomain.domain.com ONLY if I don't have anything after the domain part. This means that domain.com/node/3 should NOT be redirected.

I hope it makes sense and thank you in advance for your help :)
Ok, I've found the solution. I'm adding this to my existing nginx config:

location = / {
  rewrite ^ http://subdomain.domain.com permanent;
  break;
}


This redirects the top level domain but leaves all the existing "deep" links intact. If anybody wants to know why I'm doing this, it's good for SEO. I'm keeping the old URLs intact (as an archive) but redirect the domain to my new website.