问题
I'm trying to accomplish a rewrite in nginx, but it isn't working.
What I'm trying to do is this:
www.website.com/backstage/somepage.php?language=Dutch
should become
www.website.com/nl/backstage/somepage.php
I have added this line to the nginx config (but it isn't doing anything):
rewrite ^/nl/backstage/(.*)\.html$ /./backstage/$1.php?language=Dutch last;
I hope someone can help :) Thank you.
回答1:
humm, I don't understand your rewrite directive, it doesn't make much sense. check the doc : http://wiki.nginx.org/HttpRewriteModule and in particular
rewrite regex replacement
So you have to find a regex that matches /backstage/somepage.php?language=Dutch and replacement would be /nl/backstage/somepage.php . However, this one is tricky as you are trying to rewrite according to a parameter. So "rewrite" alone doesn't work, you have to use "if".
This should work:
if ($args ~ language=Dutch){
rewrite ^/backstage/(.*).php$ /nl/backstage/$1.php permanent;
}
来源:https://stackoverflow.com/questions/20937603/url-rewriting-nginx