Hello, I need to set some headers to all urls with certain scheme ie: http://domain.com/teenager-kills-abusive-stepfather/66585/
so i can read it something like this http://domain.com/*/*/
i have an if (I know if is evil) like this one:
if ($uri ~ "/php-fpm-status/") {
set $bypass "true";
add_header Something "value";
}
but in this case i need something like this:
if ($uri ~ "/*/*/") {
set $bypass "true";
add_header Something "value";
}
I really suck on regular expressions, so any help would be nice. or maybe a regular expressions dummy to regular tool/convertor link :D
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!
Hi!
As you said, if is indeed evil :) You should use a location block instead:
location ~ ^/(.*?)/(.*?)/?$ {
add_header name value;
}
This regular expression should match all URIs of the format /something/something with an optional trailing slash. Inside the block, you have the variables $1 and $2 available which are mapped to the first and second wildcard group (.*) respectively.
In case you’re interested, I personally like to use Regex101 to test regular expressions.
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.