ixley
@ixley

Почему не срабатывает редирект с большим количеством слешей в конце?

Читал что nginx по умолчанию обрабатывает множество слешей

Есть сайт на wordpress и там редирект работает нормально, пример:
yourdomain.ru////////////// редиректит на yourdomain.ru
или yourdomain.ru/page////////// редиректит на yourdomain.ru/page/

А есть сайт где index.html лежит в папке по адресу testimonials и редирект с yourdomain.ru/testimonials/////////////// не срабатывает

Мои настройки:
server {
root /var/www/yourdomain;
index index.php index.html index.htm index.nginx-debian.html;
server_name yourdomain www.yourdomain *.yourdomain;
location / {
if ($block_ip = 1) {
return 444;
}
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
}
location ~ /\.ht {
deny all;
}
location ~* ^/.+\.(png|gif|jpe?g)$ {
expires 30d;
add_header Pragma "public";
add_header Cache-Control "public, max-age=31536000, immutable";
add_header Vary Accept;
try_files $uri$webp_suffix $uri$avif_suffix $uri =404;
}
location ~* \.(css|js|ico|gif|jpeg|jpg|webp|avif|png|svg|eot|otf|woff|woff2|ttf|ogg)$ {
expires 30d;
add_header Pragma "public";
add_header Cache-Control "public, max-age=31536000, immutable";
}
access_log /var/log/nginx/access_yourdomain.log;
error_log /var/log/nginx/error_yourdomain.log;
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/yourdomain-0001/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/yourdomain-0001/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
if ($host = www.yourdomain) {
return 301 https://yourdomain$request_uri;
}
}
server {
listen 80;
server_name yourdomain www.yourdomain *.yourdomain;
return 301 https://yourdomain$request_uri;
if ($host = www.yourdomain) {
return 301 https://yourdomain$request_uri;
}
if ($host = www.yourdomain) {
return 301 https://$host$request_uri;
}
if ($host = yourdomain) {
return 301 https://$host$request_uri;
}
return 404;
}
  • Вопрос задан
  • 97 просмотров
Решения вопроса 1
ixley
@ixley Автор вопроса
мне помог такой вариант
location / {
try_files $uri $uri/ /index.php$is_args$args;
if ($request_uri ~ "^[^?]*?//") {rewrite "^" $scheme://$host$uri permanent;}
}


и ещё у меня есть разные html в разных папках по разным путям, там я тоже указал это правило

location ~ ^/(?<slug>[^/]+)/$ {
set $page_path /folder1/folder1/$slug.html;
try_files $uri $uri/ $page_path =404;
if ($request_uri ~ "^[^?]*?//") {rewrite "^" $scheme://$host$uri permanent;}
}

location ~ ^/(?<slug>[^/]+)/$ {
set $page_path /folder2/folder2/$slug.html;
try_files $uri $uri/ $page_path =404;
if ($request_uri ~ "^[^?]*?//") {rewrite "^" $scheme://$host$uri permanent;}
}
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

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

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