Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I want to take m.example.com and direct those requests to example.com/mobile/ with nginx. (The same nginx sever will be serving example.com)

Can someone help me with the config I would need? I can post my nginx.conf if needed, but I assume its something like:

location / { rewrite /([^/] +) /mobile/$1 break; proxy_pass; }

Am I in the right ballpark?

share|improve this question

1 Answer 1

You should use a server block for this to allow Nginx to use it's hash table lookup.

server {
    server_name m.example.com;

    location / {
        rewrite ^ http://example.com/mobile$request_uri permanent;

    location /mobile {
        rewrite ^ http://example.com$request_uri permanent;
share|improve this answer
Will this account for links like m.imax.com/mobile/main? How would I account for that? –  kkubasik Oct 31 '10 at 0:14
Edited the code example. Now it will rewrite m.example.com/mobile/main and m.example.com/main to example.com/mobile/main –  Martin Fjordvald Oct 31 '10 at 3:05

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.