URL 重写 Nginx [英] URL Rewriting Nginx

查看:54
本文介绍了URL 重写 Nginx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 nginx 中完成重写,但它不起作用.

I'm trying to accomplish a rewrite in nginx, but it isn't working.

我想要做的是:

www.website.com/backstage/somepage.php?language=Dutch

应该变成

www.website.com/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.

推荐答案

嗯,我不明白你的重写指令,它没有多大意义.检查文档:http://wiki.nginx.org/HttpRewriteModule,特别是

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

所以你必须找到一个匹配/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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆