If you directly edit .htaccess
(at the root directory of Drupal), I suppose you may as well be very careful, because any update of Drupal may delete it. For that reason, as I understand it is not recommended in general.
I have been using Redirect module for that purpose and am content with it.
With the module, you can manually set the redirection for each path in its configuration panel. But as you have hundreds of paths, perhaps you want a programmatical way.
An article by Dale McGladdery is concise and helpful for how to do that, using the module (It uses the Migration module; in your case ignore that part and set "From" and "To" URLs to suit your requirements). Basically, you use redirect_save($redirect)
function, where $redirect
is the stdClass
object, definining the paths and type of redirection.
A potential trouble in his example is, if the same redirection exists, it raises an error. Therefore if you ever rerun the process to set up the redirections, you will have a trouble. To overwrite the existing redirection, you need to appropriately set rid
of the object to pass to the funciton redirect_save()
.
I have done that in my migration, and you can have a look at the source code at GitHub (complete()
section), if you want to have a look at an example.