大网数据广告活动
服务器运维问答

nginx map rules, case insensitive

· 52CE 我爱测

I'm trying to force a URL to point to a new location. For example: site.com/Gites/ site.com/gites/ I currently have a "map" set up on the site: map $uri $is_rewrite { default no_redirect; include /home/xxx/conf/web/chambres.com.e…

问题原文

原帖链接 · Andrew Newby · CC BY-SA 4.0

I'm trying to force a URL to point to a new location. For example:

  • site.com/Gites/
  • site.com/gites/

I currently have a "map" set up on the site:

map $uri $is_rewrite {
    default     no_redirect;
    include /home/xxx/conf/web/chambres.com.extra/links.map;
}

...and inside that file, one of the rules is:

/gites/ https://$http_host;
#/Gites/ https://$http_host;
/french/Gites/ https://$http_host;

If I uncomment the 2nd line, I get an error!

nginx: [emerg] conflicting parameter "/gites/" in /home/xxx/conf/web/chambres.com.extra/links.map:107

When I test it, sure enough, the lowercase one works, but not the uppercase "Gites". How can I make it case insensative?

已采纳解答

原帖链接 · Michael Hampton · CC BY-SA 4.0

The nginx map directive is indeed documented as doing case-insensitive string matching.

Strings are matched ignoring the case.

If this is actually a problem in your case (i.e. you need different results for /gites/ and /Gites/) then you can use a regular expression match, which can be either case sensitive or insensitive.

A regular expression should either start from the “~” symbol for a case-sensitive matching, or from the “~*” symbols (1.0.4) for case-insensitive matching.

So you could match instead:

~^/gites/ https://one;
~^/Gites/ https://two;

Keep in mind that regular expressions are only checked if there are no plain string value matches in the map.

If you don't need different results for each string, then you don't need to do anything. One string match will cover all cases.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-05-13)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。