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.
1 Answer
Try this:
# output: example.com/test
rewrite ^/([A-Za-z0-9_]+)$ /page.php?username=$1;
UPDATE:
{1,35} This expression allow from 1 to 35 character
{20} That have to exactly 20 character
The + say minimum 1 character
The correct full rewrite rule:
# output: example.com/test
rewrite "^/([A-Za-z0-9_]{1,35})$" /page.php?username=$1;