NGINX-URL重写正则表达式 [英] NGINX - url rewrite regular expression
本文介绍了NGINX-URL重写正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有诸如example.com/page.php?username=test
之类的网址.我想将此URL重写为类似以下内容:example.com/test
仅当test遵循以下正则表达式时:/^[0-9a-zA-Z_-]{1,35}+$/
,否则为404页.
I have the url such as example.com/page.php?username=test
. I want to rewrite this url into something like: example.com/test
only if test follows the following regual expression: /^[0-9a-zA-Z_-]{1,35}+$/
, else 404 page.
推荐答案
尝试一下:
# output: example.com/test
rewrite ^/([A-Za-z0-9_]+)$ /page.php?username=$1;
更新:
{1,35}
此表达式允许输入1到35个字符
{1,35}
This expression allow from 1 to 35 character
{20}
必须精确到20个字符
{20}
That have to exactly 20 character
+
说出至少1个字符
正确的完全重写规则:
# output: example.com/test
rewrite "^/([A-Za-z0-9_]{1,35})$" /page.php?username=$1;
这篇关于NGINX-URL重写正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文