I need to get only part of the $host variable. Domain is in the form img1.domain.com and I need to get "domain.com" and then use it in redirect.
I am trying it wrong like this:
$host ~* img[0-9]\.(.*);
set $host_without_img $1;
I know it would work, if I would put in in IF condition like this:
if ($host ~* img[0-9]\.(.*)) {
set $host_without_img $1;
}
But I just don't want to use IF, when it is not necessary.
You can use map, something like this:
map $host $host_without_img {
default ...;
~*img[0-9]\.(?<x_host_without_img>.*) $x_host_without_img;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With