@Volton

Как сделать 301 редирект в Nginx одной страницы на главную?

Сайт работает по https. Настроены редиректы с www на non-www.
Есть одна внешняя старая ссылка, ведущая на сайт, типа site.com/index.htm и я хочу редиректитить ее на главную https://site.com
Подскажите, пожалуйста, как это сделать. Я уже исчерпал все варианты... Привожу пример конфига:

server {
    listen      80;
    server_name site.com  www.site.com;
    return      301 https://site.com$request_uri;
}

server {
    listen      443 ssl;
    server_name www.site.com;

    ssl_certificate     /etc/nginx/ssl/site_com/sitecom-ssl-bundle.crt;
    ssl_certificate_key /etc/nginx/ssl/site_com/site_com.key;

    return      301 https://site.com$request_uri;
}

server {
    listen      443 ssl;
    server_name site.com;

    ssl_certificate     /etc/nginx/ssl/site_com/sitecom-ssl-bundle.crt;
    ssl_certificate_key /etc/nginx/ssl/site_com/site_com.key;
    # other settings ssl

    root /var/www/site.com;
    index index.html;

    location /robots.txt {
        alias /var/www/site.com/public/robots.txt;
        access_log off; log_not_found off;
    }

    location / {
        try_files $uri $uri/ =404;
    }
}


Пробовал:
if ( $request_filename ~ index.htm ) {
        rewrite ^ http://site.com? permanent;
    }

rewrite ^/index.htm$ https://site.com$1 permanent;

и другие конструкции, но не получилось(
  • Вопрос задан
  • 4389 просмотров
Решения вопроса 1
@RidgeA
так не пробовал?
location = /index.html {
    return 301 https://site.com
}
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы