Nginx的子域路由redirect不工作

这是我在nginx_conf文件中的服务器块:

我正在使用cloud66,所以我可以从我的仪表板进行编辑。

这不断打破。 我怀疑这是因为我的条件和声明。

我正在尝试将以下url转到以下url:

http://subdomain.domain.com/notes.php并将其路由到/ dashboard将其路由到http://domain.com/dashboard

http://subdomain.domain.com/contact-us.php并将其路由到/ dashboard将其路由到http://domain.com/contact-us/new

http://subdomain.domain.com/help.php并将其路由到/ dashboard将其路由到http://domain.com/faq

server { ... # redirect old routes on subdomain server_name ~^www\.(?<domain>.+)$; if ($host ~ "^(.*)$domain") { set $subd $1; if $1 = 'notes.php'{ rewrite ^(.*) /dashboard permanent; } if $1 = 'contact-us.php'{ rewrite ^(.*) /contact-us/new permanent; } if $1 = 'help.php'{ rewrite ^(.*) /faq permanent; } } } 

当我把这个错误,我得到以下错误:

 + server + { + server_name secure.inrtracker.com www.secure.inrtracker.com; + + location = /notes.php { + rewrite ^ /dashboard permanent; + } + } 

发生错误。 对不起,您正在寻找的页面目前无法使用。 请稍后再试。 如果你是这个资源的系统pipe理员,那么你应该检查错误日志的细节。 忠实于你,nginx。

首先:强制性如果是邪恶的

其次,你应该分开你的子域和域到不同的服务器块(和/或不同的文件)。 然后创build重写规则

 server { server_name oursubdomain.domain.com www.oursubdomain.domain.com; location / { rewrite ^/notes.php$ $scheme://domain.com/dashboard permanent; rewrite ^/contact-us.php$ $scheme://domain.com/contact-us/new permanent; rewrite ^/help.php$ $scheme://domain.com/faq permanent; } } server { server_name domain.com www.domain.com; location = /dashboard { # Do something here, possibly send to php } location = /faq { # Do something here, possibly send to php } location = /contact-us/new { # Do something here, possibly send to php } } 

我希望在你的路上帮助你!