URL 重写 Nginx

编程入门 行业动态 更新时间:2024-10-28 13:15:00
本文介绍了URL 重写 Nginx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试在 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

本文发布于:2023-10-31 17:10:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546739.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重写   URL   Nginx

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!