I’m trying to configure Nginx so that any request to:
https://redirectx.com/<id>
—where <id> is exactly six lowercase letters or digits—will be redirected to:
https://domainx.com/instant/?lid=<id>
If <id> doesn’t match that pattern, I want to return a 200 response with a plain-text message:
Invalid link, please try again
So far I have this in my server block:
Redirect exactly six lowercase alphanumeric characters
rewrite ^/([0-9a-z]{6})$ https://domainx.com/instant/?lid=$1 permanent;
Catch-all fallback for anything else
location / {
default_type text/plain;
return 200 'Invalid link, please try again';
}
…but it’s not working. Requests to /4k9j2m, /t3q8f7, etc. are not being redirected, and the fallback block never fires either.
Any help would be greatly appreciated!
Thanks
Jan