加入收藏 | 设为首页 | 会员中心 | 我要投稿 阜阳站长网 (https://www.0558zz.com/)- 科技、建站、内容创作、云计算、网络安全!
当前位置: 首页 > 运营中心 > Nginx > 正文

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

发布时间:2021-01-11 23:55:33 所属栏目:Nginx 来源:互联网
导读:我的vhost conf中有以下正则表达式:location ~* ^/!/[^a-zA-Z0-9] { return 301 $scheme://$http_host; } 但它似乎只与第一个字符匹配:# Redirects to https://shouttag.com correctly https://shouttag.com/!/!pink

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

(编辑:阜阳站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读