【问题标题】:Optional / on end of an URL可选 / 在 URL 的末尾
【发布时间】:2017-01-06 05:30:59
【问题描述】:

我今天发现,如果我打开我的 URL 时使用 / 结束或不是为了重写规则,它是不一样的。

# Pokedex
rewrite (?i)^\/Pokemon-Go-Pokedex\/$            /i.php?p=pokedex last;
rewrite (?i)^\/Pokemon-Go-Pokedex\/+([A-Za-z0-9]+)$     /i.php?p=pokedex&pokemon=$1 last;

如果我现在打开 domain.com/Pokemon-Go-Pokedex/ 一切正常。但是domain.com/Pokemon-Go-Pokedex 没有。现在我寻找一种方法,使 / 成为可选的。

我尝试了什么(但 nginx-config-test 失败了)

rewrite (?i)^\/Pokemon-Go-Pokedex+([\/]){0,1}$
rewrite (?i)^\/Pokemon-Go-Pokedex+([\/]{0,1})$

在 RegExr.com 上,此 (//Pokemon-Go-Pokedex+[/]{0,1}) 有效,机器人不在配置中,所以我需要帮助。

【问题讨论】:

  • 这正是我正在寻找的。如果您发布它,作为答案,我可以确认它。非常感谢。

标签: regex nginx url-rewriting


【解决方案1】:

? 使前一个字符/组成为可选的。

rewrite (?i)^\/Pokemon-Go-Pokedex\/?$

【讨论】:

    猜你喜欢
    • 2017-06-15
    • 2021-05-05
    • 1970-01-01
    • 1970-01-01
    • 2021-04-08
    • 1970-01-01
    • 2016-04-13
    • 2014-02-03
    • 2011-12-11
    相关资源
    最近更新 更多