Setting up a lot of 301 redirects?

Hello everyone, we have a larger website project where we now have to set up about 10,000 301 redirects.

I've already come to the conclusion that it's definitely not a good idea to include all redirects in the htaccess, as this is always reloaded when a website request is processed.

The vhost should be a good solution here.
Unfortunately, we only have a larger web hosting system where you don't get access to the vhost, only with a vServer.

So I wanted to ask if there was another option. Thank you.

(1 votes)
Loading...

Similar Posts

Subscribe
Notify of
9 Answers
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Destranix
1 year ago

You can code your own redirect script on the server side. In the language your web server uses (e.g. PHP).

You can then use a database or something in the background.

Destranix
1 year ago
Reply to  sinuss

You send the appropriate headers from your server as an answer and then finish the session or give something matching.

Example:

header("HTTP/1.1 301 Moved Permanently");
            $url = "https://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
            $queryPos = strpos($url, "?");
            if($queryPos === FALSE){
                $anchorPos = strpos($url, "#");
                if($anchorPos === FALSE){
                    $url .= "?redirected=true";
                }else{
                    $url = substr($url, 0, $anchorPos)."?redirected=true".substr($url, $anchorPos);
                }
            }else{
                $url = substr($url, 0, $queryPos+1)."redirected=true&".substr($url, $queryPos+1);
            }
            header("Location: ".$url);
            exit();

(I think that redirected to HTTPS.)

Destranix
1 year ago

That you just create a redirect table and you only get the right entry you just need.

There you can also implement a cache or something, certainly somehow. (Apparently, a suitably configured database can allow quick access on the one hand, and can also operate caching on the other hand.)

You get the input URL from the user, make a query in the database (by means of pre-indicated and pre-optimized query) and you get the target URL that you then use as above in the code example (send header, then place location, then exit).

Destranix
1 year ago

You can dynamically load the redirects from a database or other data structure. You have to code accordingly.

triopasi
1 year ago

What do you need so many redirects for? This sounds more like using forwarding rules or properly configuring the web server. I don’t know any sensible application that so many manual redirects need. Maybe you should have the problem or Describe your goal and not your presumed solution.