I have http:// and https:// on the same host like the following:
server {
listen 80;
listen 443 ssl;
...
...
}
What I
In order to use regular expressions for matching locations, you need to prefix the expression with either ~
or ~*
:
if ($server_port = 80) {
location ~ (en|fr)/shop {
rewrite ^ https://$host$request_uri permanent;
}
}
From the documentation:
To use regular expressions, you must use a prefix:
"~"
for case sensitive matching"~*"
for case insensitive matching
Since nginx does't allow location
blocks to be nested inside of if
blocks, try the following configuration:
if ($server_port = 80) {
rewrite ^/(en|fr)/shop https://$host$request_uri permanent;
}