I'm trying to redirect 15 different routes with Nginx from folders to subdomains (I already read some threads about this).
I'm very confused because this redirect is working:
rewrite ^/admin(.*) $scheme://admin.example.com/$1 301;
while this one is not (the url is not changed in my browser):
rewrite ^/app(.*) $scheme://apps.example.com/$1 301;
What did I miss ?
At the time, I have only these 2 redirects (I need 15 more complicate later).
EDIT: more explanations with my full nginx config
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name example.com;
passenger_enabled on;
rails_env production;
root /home/admin/rails/current/public;
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# redirects
# admin
rewrite ^/admin(.*) $scheme://admin.example.com/$1 302;
# apps
rewrite ^/app(.*) $scheme://apps.example.com/$1 302;
}
EDIT 2: asked by Tom, What I want to do exactly (I prefer to keep the URL secret):
GET http://example.com => http://apps.example.com
GET http://example.com/app => http://apps.example.com
GET http://example.com/app/iphone => http://apps.example.com/iphone
GET http://example.com/app/ipad => http://apps.example.com/ipad
GET http://example.com/support/iphone => http://apps.example.com/support/iphone
GET http://example.com/support/ipad => http://apps.example.com/support/ipad
GET http://example.com/legal/privacy?params=toto => http://apps.example.com/legal/privacy?params=toto
GET http://example.com/legal/terms?params=toto => http://apps.example.com/legal/terms?params=toto
GET http://example.com/legal/about => http://apps.example.com/legal/about
I have also a few POST to redirect but I think I need a proxy for that, isn't it ?
Thanks in advance.
EDIT 3: so here are my GET redirects after Tom answer:
# pages to redirect to admin.$host
location /admin { return 301 $scheme://admin.$host; }
# pages to redirect to apps.$host
location /app { return 301 $scheme://apps.$host; }
location /app/iphone { return 301 $scheme://apps.$host/iphone; }
location /app/ipad { return 301 $scheme://apps.$host/ipad; }
location /support/iphone { return 301 $scheme://apps.$host/support/iphone$is_args$args; }
location /support/ipad { return 301 $scheme://apps.$host/support/ipad$is_args$args; }
location /legal/privacy { return 301 $scheme://apps.$host/legal/privacy$is_args$args; }
location /legal/terms { return 301 $scheme://apps.$host/legal/terms$is_args$args; }
location /legal/about { return 301 $scheme://apps.$host/legal/about; }
It is working great !
Now, I will open a new thread cos' I can't create POST redirect with my proxy_pass. See there.