I would like to alias m.example.com
so that the requests are forwarded/aliased to example.com/m/
but without the user being redirected to the /m/
directory.
For example, the user accesses m.example.com
, m.example.com/1.htm
, m.example.com/2.htm
but nginx is forwarding/aliasing the requests to example.com/m/
, example.com/m/1.htm
and example.com/m/2.htm
.
I have tried to use the rewrite
directive, but this appears to perform a client-side redirect to example.com/m/
.
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:
server_name example.com m.example.com;
...
if ($host ~* m\.(.*))
{
rewrite ^(.*)$ http://example.com/m$1 break;
}
Another attempt:
server
{
listen 80;
server_name m.example.com;
location /
{
rewrite ^ http://example.com/m$request_uri permanent;
}
}
Thanks in advance.