【问题标题】:Proper nginx rewrite rule正确的 nginx 重写规则
【发布时间】:2015-09-27 16:12:16
【问题描述】:

nginx重写规则怎么做转换

example.com/?subtopic=forum&action=show_board&id=1

进入这个

example.com/forum/board/1

或者这个

example.com/?subtopic=characters&name=永恒

进入这个

example.com/characters/Eternal

我已经找到并尝试使用此代码

location / {
            rewrite ^/subtopic/(.*)$ /?subtopic=$1 last;
    }

但它不起作用(我真的是重写的新手)

【问题讨论】:

  • 将规则更改为此rewrite ^(.*)$ /?subtopic=characters&name=$1 last; 和它的一个步骤,它识别链接中的某些内容,但是当我尝试查看字符页面时,它说 字符/永恒不存在。我>

标签: nginx rewrite


【解决方案1】:

你可以试试这些规则:

rewrite /(.*)/(.*)/(\d+) /?subtopic=$1&action=show_$2&id=$3 last;
rewrite /(.*)/(.*)       /?subtopic=$1&name=$2 last;

【讨论】:

  • 应该还在location / {}下吗?
  • @Rafau 它应该在location之外。
  • 试过了,它只有在我进入之前的 url http://www.example.com/ban 时才有效:http://example.com/?subtopic=ban 如果我尝试另一个类似字符的 url - 它由于某种原因不起作用(它可能是我的网站,会尝试一些事情)
  • @Rafau 尝试添加第三条规则:rewrite /(.*) /?subtopic=$1 last;
猜你喜欢
  • 2010-11-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-05
  • 1970-01-01
  • 1970-01-01
  • 2015-03-04
相关资源
最近更新 更多