Как установить 301 редирект на Nginx?

ЛЛ
На сайте с 12.11.2018
Offline
68
264

Добрый день всем. Все мозги себе перевернул никак не могу понять как сделать 301 редирект с одной страницы на другую. Сервер настраивал отдельный человек. Уже все гайды и мануалы пролистал.

Такая конфигурация:

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

server {
listen 443 ssl http2;
server_name www.site.ru;

ssl_certificate /etc/letsencrypt/live/site.ru/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/site.ru/privkey.pem;

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


server {
listen 443 ssl http2;
server_name site.ru;
keepalive_timeout 70;

ssl_certificate /etc/letsencrypt/live/site.ru/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/site.ru/privkey.pem;

ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;

root /var/www/site.ru/;

# Add index.php to the list if you are using PHP
index index.php;

location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
#try_files $uri $uri/ =404;
try_files $uri /index.php?$uri&$args;
}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#
# # With php7.0-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php7.0-fpm:
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}

location ~* \.(ico|css|js|gif|jpeg|jpg|png|woff|ttf|svg)$ {
add_header "Access-Control-Allow-Origin" "*";
root /var/www/site.ru/;
expires 3d;
add_header Pragma public;
add_header Cache-Control "public";
}

location ~ /(internal_data|library) {
internal;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}


Пробовал:

server {
#...
if ( $request_filename ~ oldpage/ ) {
rewrite ^ http://www.devreadvrite.com/newpage/? permanent;
}
#...
}

И прочие вариации с мануалов. Смилуйтесь помогите побороть эту проблему.

IL
На сайте с 20.04.2007
Offline
435
#1
Лелуш Ламперуж:
Уже все гайды и мануалы пролистал.

Одного вполне достаточно было бы https://www.nginx.com/blog/creating-nginx-rewrite-rules/

Или документации.. https://nginx.org/en/docs/http/ngx_http_rewrite_module.html#rewrite


rewrite ^/oldpage/$ /newpage/ permanent;

... :) Облачные серверы от RegRu - промокод 3F85-3D10-806D-7224 ( http://levik.info/regru )

Авторизуйтесь или зарегистрируйтесь, чтобы оставить комментарий