URL Rewriting Nginx

随声附和 提交于 2019-12-25 06:44:50

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!