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?

up vote 0 down vote accepted

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:
https://github.com/mlutfy/provision_customhtaccess

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:
https://www.drupal.org/node/2118233

You can see how drupal_match_path() does a match and use that to rewrite the target redirect:
https://api.drupal.org/api/drupal/includes!path.inc/function/drupal_match_path/7

  • this is a pretty good answer, thanks. – Tom Oct 24 '14 at 17:16

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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