I need to move a legacy Drupal 7 site to our new Aegir hosting environment. Unfortunately, the file structure is "non standard". I need to move drupal/materials to drupal/sites/default/files/materials but also need a corresponding path rewrite or redirect .htaccess or http.config is not an option, I need to do it in Drupal.

Redirect module does not do tokens or wild cards. Match_redirect module does not rewrite, but matches on a many to one bases. A rewrite would be better than a redirect.

I cant seem to find an existing contrib - how would I do this in PHP with the Drupal APIs? Would I want to use hook_boot or hook_init?

1 Answer 1


If you have some control on the Aegir instance, and 100% trust your users that have sftp/ssh access to your site, you could use the provision_customhtaccess module:

This makes it possible to have a "htaccess-custom" file in your sites/example.org/ directory that will get included in your vhost configuration. However, it is a big security risk if you do not trust your users. They can close a vhost declaration, open a new one, do many bad configurations, etc.

Alternatively, if you're going to write a new module, it seems pretty easy to add in the match_redirect module. There is a feature request open, so I am sure the community would appreciate. Worst case, you can offer the maintainer to sponsor the development:

You can see how drupal_match_path() does a match and use that to rewrite the target redirect:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.