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;
}

相关文章

文章浏览阅读3.7k次,点赞2次,收藏5次。Nginx学习笔记一、N...
文章浏览阅读1.7w次,点赞14次,收藏61次。我们在使用容器的...
文章浏览阅读1.4k次。当用户在访问网站的过程中遇到404错误时...
文章浏览阅读2.7k次。docker 和 docker-compose 部署 nginx+...
文章浏览阅读1.3k次。5:再次启动nginx,可以正常启动,可以...
文章浏览阅读3.1w次,点赞105次,收藏182次。高性能:Nginx ...