P
P
Pista2020-08-14 16:26:07
Nginx
Pista, 2020-08-14 16:26:07

How to redirect a domain alias to a specific page in the main domain in Nginx?

Added an alias to the main domain, the task is to redirect the alias to a specific page of the main domain.
server
{
listen 443 ssl http2;
server_name domain.ru;
ssl_certificate /etc/letsencrypt/live/sexyou.cyou/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/sexyou.cyou/privkey.pem; # managed by Certbot
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
ssl_prefer_server_ciphers on;
ssl_dhparam /var/www/ssl/dhparam.pem;
add_header X-Content-Type-Options nosniff;

server_name alias.domain.ru;
return 301 $ scheme://$host/link/landing$request_uri ;

The problem is that when I access alias.domen.ru , I see domen.ru/link/landing/link/landing/link/landing/link/landing/link/landing/link/landing/link in the address bar /landing/link/landing/link/landing/link/landing/link/landing/link/landing/link/landing/link/landing

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2020-08-14
@Pista

move alias.domen.ru to a separate server block.

server {
    listen 443 ssl http2;
    server_name alias.domen.ru;
    ssl_certificate   ... ;
    ssl_certificate_key ... ;

    return 301 https://domen.ru/link/landing;
}

Or leave as is and add ifto avoid looping.
if ($host = alias.domen.ru) {
    return 301 https://domen.ru/link/landing;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question