B
B
bigdogsru2014-01-10 03:54:13
Nginx
bigdogsru, 2014-01-10 03:54:13

How to register many redirects of specific pages?

There is a site consisting of separate html pages, with names that mean nothing like index1.htm, index10.htm, index130.htm, Page1.html, page20.htm, etc. Domain older than five years, unique content, very good positions in search engines.
And there is a new version of the site - on a CMS with CNC, about half of the pages of the new version can be specifically compared with the old one, for which the customer compiled a neat sign
index117.htm - /news/
index5.htm - /news/novost-pro-chto-to- konkretnoye/
... and so on. There are no matches in the addresses of the old and new site - simply because it is insanity, to save all these numbered indexes and pages on the CNC CMS.
The new version is still on the subdomain, on the Apache server and nginx as a proxy on the frontend.
The old site will not be transferred to this server - the domain will simply be switched to a new IP.
All page matches must be written as 301 redirects.
I think it's better to do it in nginx? How to do it right? All the examples for nginx that I managed to google for some reason contain both the protocol and the domain ( http://site.ru/new-page/) in the address to which you need to redirect. Is it possible to prescribe without protocol and domain?
And if you still need to do this in Apache, then why?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladlen Grachev, 2014-01-10
@bigdogsru

I did it at the PHP level. I collected an associative array, where the key is the old address, and the value is the new one. And then in the 404 error handler, I put a condition at the beginning that if an element with a key corresponding to the current request is found in that array, then a redirect is made.
Code example:

foreach ($links as $old_link => $new_link) {
    if ($old_link == $_SERVER['REQUEST_URI']) {
        header("HTTP/1.1 301 Moved Permanently");
        header("Location: $new_link");
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question