Метка

nginx

Всего: 8 записей

nginx redirect to https

Полный редирект:

if ($scheme != "https") {
	return 301 https://$host$request_uri;
}

Редирект всего кроме robots.txt

set $do_redirect 1;
if ($scheme ~* ^https$) {
	set $do_redirect 0;
}
if ($request_uri ~* ^/robots\.txt$) {
	set $do_redirect 0;
}
if ($do_redirect = 1) {
	return 301 https://$server_name$request_uri;
}

nginx .htaccess

Для конвертации правил можно воспользоваться сервисами:
https://winginx.com/ru/htaccess
http://www.anilcetin.com/convert-apache-htaccess-to-nginx/

nginx header 301 404

Когда с несуществующей страницы нужно сделать, например, редирект.

Чтобы разрешить изменение кода ответа HTTP с 404 на другой (например, 301 для постоянного перенаправления), вам необходимо настроить директиву Nginx error_page:

error_page 404 = /404.php;

Т.е. вместо:

error_page 404 /404.php;

Без знака равенства (=) невозможно изменить код состояния с помощью PHP-скрипта:

header("Location: /new.html",true,301);

https://stackoverflow.com/questions/20932750/redirect-instead-of-404-error-page-status-code-not-working-nginx

Redirect instead of 404 Error page — Status Code not working (Nginx)
To allow changing the HTTP response code from 404 to a different one (e.g. 302 for the temporary redirect), you have to configure Nginx error_page directive accordingly:

error_page 404 = /404.php;

Without the equal sign (=), it is not possible to change the status code with your PHP script:

header("Location: http://google.com");