S
S
seotuning2018-09-04 16:00:28
Nginx
seotuning, 2018-09-04 16:00:28

How to set up a 301 redirect for 404 pages?

There is a site mocah.org , recently 404 errors have begun to appear. For example, https://mocah.org/xfsearch/alt/EVE/page/33/, this happened due to the fact that the amount of news on the EVE tag has changed. I would like to redirect from such 404 pages to the first page of the tag, i.e. https://mocah.org/xfsearch/alt/EVE/. I already found a similar problem and solution on the toaster, but my url structure is slightly different. Here's a thread - Nginx how to make a redirect for certain uris returning 404? And here is the solution -

error_page 404 =404 /404.html;
location ~* \.php$ {
include fastcgi_def;
include add/cachephp;
if ($request_uri ~ /(.+)/page-\d+\.html) {
error_page 404 = @page;
}
fastcgi_intercept_errors on;
}
location / {try_files $uri /index.php?$args;}

location @page {
if ($request_uri ~ /(.+)/page-\d+\.html) {return 301 /$1.html;}
return 410;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Marat, 2018-09-05
@Xakki

Do a redirect on the backend, you should not do this on nginx

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question