I want to redirect all the entries for a certain subdirectory to another (external) domain with the "rest" of the address. I have tried something but it does not work...
server {
listen [::]:443 ssl;
listen 443 ssl;
server_name cahiers.example.fr cahiers.example.eu.org;
return 301 https://publications.example.fr/cahiers;
ssl_certificate /etc/letsencrypt/live/publications.example.fr/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/publications.example.fr/privkey.pem; # managed by Certbot
}
# Bloc pour la redirection vers le HTTPS.
server {
location ^~ /subdir(.*) {
return 301 https://external.org/$1;
}
if ($host = cahiers.example.fr) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = cahiers.example.eu.org) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
listen [::]:80;
server_name cahiers.example.fr cahiers.example.eu.org;
return 301 https://$host$request_uri;
}
What am I doing wrong?
Thanks