NGINX-正则表达式-在整个位置搜索非字母数字

前端之家收集整理的这篇文章主要介绍了NGINX-正则表达式-在整个位置搜索非字母数字 前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我的vhost conf中有以下正则表达式:

location ~* ^/!/[^a-zA-Z0-9] {
    return 301 $scheme://$http_host;
}

但它似乎只与第一个字符匹配:

# Redirects to https://shouttag.com correctly
https://shouttag.com/!/!pink

# Does not redirect as expected
https://shouttag.com/!/p!nk

我尝试过的变化:

# Assume that $is unnecessary b/c I don't know what the end of the url may be
location ~* ^/!/[^a-zA-Z0-9]${

# Only seems to work when capturing data via group Syntax ()
location ~* ^/!/[^a-zA-Z0-9]+ {

谢谢.

最佳答案
您可以尝试以下规则:

location ~ ^/!/[a-zA-Z0-9]*[^a-zA-Z0-9].*${
    return 301 $scheme://$http_host;
}
原文链接:https://www.f2er.com/nginx/532284.html

猜你在找的Nginx相关文章