我正在尝试在 nginx 中完成重写,但它不起作用.
I'm trying to accomplish a rewrite in nginx, but it isn't working.
我想要做的是:
www.website/backstage/somepage.php?language=Dutch应该变成
www.website/nl/backstage/somepage.php我已将此行添加到 nginx 配置中(但它什么也没做):
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.
推荐答案嗯,我不明白你的重写指令,它没有多大意义.检查文档:wiki.nginx/HttpRewriteModule,特别是
humm, I don't understand your rewrite directive, it doesn't make much sense. check the doc : wiki.nginx/HttpRewriteModule and in particular
rewrite regex replacement所以你必须找到一个匹配/backstage/somepage.php?language=Dutch 的正则表达式和替换将是/nl/backstage/somepage.php .但是,当您尝试根据参数进行重写时,这很棘手.所以单独重写"是行不通的,你必须使用if".
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".
这应该有效:
if ($args ~ language=Dutch){ rewrite ^/backstage/(.*).php$ /nl/backstage/$1.php permanent; }更多推荐
URL 重写 Nginx
发布评论