A
A
Alexey2019-12-05 19:21:16
Nginx
Alexey, 2019-12-05 19:21:16

How to set up a redirect from all levels of subdomains except 3?

Hello! I set up auto-subdomains of the 3rd level with a wildcard certificate on the site.
The question on a subject interests. Example:
sub1.example.ru - ok
www.sub1.example.ru - ok
sub2.sub1.example.ru - redirect to the main domain
sub3.sub2.sub1.example.ru - redirect to the main domain
subN..... sub1.example.ru - redirect to the main
nginx domain has the following config:

server {
  server_name _;
  listen 80;
  return 301 https://$host$request_uri;
}

server {

    listen 443 ssl http2;
    server_name example.ru *.example.ru;

    include snippets/ssl.conf;
    root $root_path;
    set $root_path /www/example.ru;
    set $php_sock unix:/var/run/php-fpm/www.php-fpm.sock;
    
     index index.html index.php;

    # redirect www to non-www
    if ($host ~* "www\.(.*)$") {
        return 301 https://$1$request_uri;
    }
    
  ### пытался сделать так, но ругается на сертификат
    if ($host ~* "^(.*?)\.([^.]+)\.example\.ru$") {
        return 301 https://example.ru$request_uri;
    }

....
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
web-mechanic, 2019-12-18
@amfetamine

some kind of game, let the SEOs at least read the basics of SEO

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question