redirect - Nginx variable for subdomain? -


i need guru's advice.

on nginx's conf file, subdomain variable in order redirect accesses follow.

  • access: http://userx.example.com/?hoo=bar
  • redirect: http://example.com/userx/?hoo=bar

but get

  • redirect: http://example.com/userx.example.com/?hoo=bar

my current _http.conf settings below. works so.

## default http server {     listen       80;     server_name  default_server;     return       301 http://example.com/$host$request_uri; } 

are there vaiables or ways below?

## default http server {     listen       80;     server_name  default_server;     return       301 http://example.com/$subdomain$request_uri; } 

i know if subdomain part limited can redirected, have add them each time , want keep simple possible.

is there simple way so?

[env]: centos:7.3.1611, nginx: nginx/1.13.3, *.example.com targetted same server in ns settings.

you can use regular expression in server_name extract part need named capture. example:

server {     listen       80;     server_name  ~^(?<name>.+)\.example\.com$;     return       301 http://example.com/$name$request_uri; } 

see this document more.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -