如果url的前5位数字是数字,我需要在nginx中设置一个位置参数。
site.com/12345/ or site.com/12345但我不能为我的一生得到正确的正则表达式。
这些都不管用。
location ^/([0-9]) { }
location ^/(\d\d\d\d\d) {}
location /(\d\d\d\d\d) {}发布于 2013-04-29 04:24:01
尝尝这个
location ~ "^/[\d]{5}" {
# ...
}~的意思是正则表达式的位置
^表示行的开头
[\d]是字符类匹配数字的缩写。
{5}显示数字必须正好是5,不多,也不差。
如果不想使用分组,例如$1,则不需要使用()括号。
双引号,因为regex中使用的curley大括号必须用双引号括起来:https://stackoverflow.com/questions/14684463/curly-braces-and-from-apache-to-nginx-rewrite-rules
发布于 2013-04-26 19:54:32
尝试这个语法(在我的服务器上测试):
location ~ ^/([0-9]+) {
#...
}https://serverfault.com/questions/503002
复制相似问题