Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to alias so that the requests are forwarded/aliased to but without the user being redirected to the /m/ directory.

For example, the user accesses,, but nginx is forwarding/aliasing the requests to, and

I have tried to use the rewrite directive, but this appears to perform a client-side redirect to

I have also had a look at the alias directive, but this only seems to modify the location of where the files will be served on the server's filesystem.

I'm sure this must have been done before, but I cannot seem to work this out. Am I using an incorrect flag with the alias directive (I've tried all 4: last, break, redirect, permanent). Have I missed the correct directive to use altogether?

Snippet of config using rewrite:



if ($host ~* m\.(.*))
    rewrite ^(.*)$$1 break;

Another attempt:

    listen            80;

    location /
        rewrite ^$request_uri permanent;

Thanks in advance.

share|improve this question
up vote 1 down vote accepted

This is not possible in Nginx. You can use the m subdomain but you will have to pass to your backend in that server block. This is because Nginx cannot rewrite the URL without using an actual HTTP redirect, even if you tell it to it will ignore that and force a HTTP redirect.

If you use a fastcgi backend it shouldn't really matter, though, and even if you proxy pass to Apache you should still be able to configure it to not care.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.