I have an SSL certificate Wildcard and nginx. I want to redirect top-level subdomains to the first-level subdomain.
You can use the following configuration in nginx:
server {
listen 80;
server_name ~^(?<anyelse>.*)\.(?<subdomain>[\w-]+)\.com\.pe$;
return 301 https://$subdomain.com.pe$request_uri;
}
server {
listen 443;
ssl on;
server_name ~^(?<anyelse>.*)\.(?<subdomain>[\w-]+)\.com\.pe$;
return https://$subdomain.com.pe$request_uri;
}
server {
listen 443;
ssl on;
server_name ~^(?<subdomain>[\w-]+)\.com\.pe$;
add_header Strict-Transport-Security "max-age=31536000;" always;
ssl_certificate /etc/nginx/ssl/cert.crt;
ssl_certificate_key /etc/nginx/ssl/cert.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
.
.
.
}