I’m using a location block to respond to requests at http://domain.com/v3/ but I want requests for resources like /v3/accounts/ to be passed to the application as simply /accounts/.
I’ve configured the following rewrite rule in the location block, but I was reading about taxing rewrites in the NGINX docs and I was hoping somebody could tell me if I’ve written the wrong type of regex for this rewrite:
rewrite ^/v3/(.*)$ /$1 break;
Thank you!
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Heya,
Just came across this answer and decided to write some general guidelines for anyone who comes across this in the future despite the old question.
The rewrite rule you’ve shared rewrite ^/v3/(.*)$ /$1 break; looks correct for your requirements. This rule essentially strips the /v3 part from the beginning of the requested URL.
The ^/v3/(.*)$ part of the rule is a regular expression that matches any URL that starts with /v3/. The .* matches any character in the URL after /v3/. Combined, they match /v3/ followed by anything.
The /$1 part of the rule is where matched URLs get rewritten to. $1 is a special variable that contains the value matched by the .* in the regular expression.
The word break at the end of the rule stops processing further rewrite rules if this one matches.
Hope that this helps!
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.