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.
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.
would you have been a rough example of this?
You send the appropriate headers from your server as an answer and then finish the session or give something matching.
Example:
(I think that redirected to HTTPS.)
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).
All in all, it’s about not always sending everything to the Apache, but how you write about if necessary php/database that makes “calculations”.
You can dynamically load the redirects from a database or other data structure. You have to code accordingly.
ah cool anke, but yes then the many redirects will be loaded with every call.
vhost has the advantage of caching :/
But thanks to you, we will examine it more closely.
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.
The website is a shop with approx. 9000 indexed pages, these change through a relaunch.
YES there are also many “rules” set up, but then there are still far over 2000 redirects that should not always come out of the htaccess.
here an info: https://ask.metafilter.com/2178/I-need-to-redirect-about-10000URLs
a solution: https://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritemap