Url rewriting NGINX-url重写正则表达式
我有一个url,比如example.com/page.php?username=test。我想将此url重写为:example.com/test,但前提是test遵循以下常规表达式:/^[0-9a-zA-Z_-]{1,35}+$/,否则为404页。尝试以下操作:Url rewriting NGINX-url重写正则表达式,url-rewriting,nginx,Url Rewriting,Nginx,我有一个url,比如example.com/page.php?username=test。我想将此url重写为:example.com/test,但前提是test遵循以下常规表达式:/^[0-9a-zA-Z_-]{1,35}+$/,否则为404页。尝试以下操作: # output: example.com/test rewrite ^/([A-Za-z0-9_]+)$ /page.php?username=$1; 更新: {1,35}此表达式允许1到35个字符 {20} 必须精确到20个字符
# output: example.com/test
rewrite ^/([A-Za-z0-9_]+)$ /page.php?username=$1;
更新:
{1,35}此表达式允许1到35个字符
{20} 必须精确到20个字符
+表示至少1个字符
正确的完全重写规则:
# output: example.com/test
rewrite "^/([A-Za-z0-9_]{1,35})$" /page.php?username=$1;
试试这个:
# output: example.com/test
rewrite ^/([A-Za-z0-9_]+)$ /page.php?username=$1;
更新:
{1,35}此表达式允许1到35个字符
{20} 必须精确到20个字符
+表示至少1个字符
正确的完全重写规则:
# output: example.com/test
rewrite "^/([A-Za-z0-9_]{1,35})$" /page.php?username=$1;