1

In short: Can I have a separate .htaccess file per site on a multi-site installation?

I've read quite a lot of conflicting stuff about this, including some which suggests you can put a .htaccess file in the site folder (i.e. /sites/www.site1.com/). However, some commenters seem to be saying this won't work.

As I am moving several non-Drupal sites over to a single multisite there will need to be lots of rewrites for old URLs, so this is pretty much essential for me.

Thanks, Chris

1 Answer 1

3

Multisite logic (picking what site is what) works in Drupal itself, rather than the Apache level.

I do not think that putting a .htaccess in the sites folder would work, mainly because nothing is really fetched from there from Apache's perspective, except for files. Normal URLs would never see that file. There would also be some weirdness with the RewriteBase, and other complications because of the way .htaccess gets processed up the directory hierarchy.

My suggestion would be to use the Redirect module. This module essentially presents a UI for making and managing redirects for your Drupal site. You can enable this per site in your multisite setup. Therefore each domain could redirect its own URLs. I have found this module very useful for new site launches that use a new URL scheme.

Your other option would be to RewriteCond, eg

RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule some/old/url.html the/new/url [L,R=301]

I would do this as an include from the main Apache configuration, rather than .htaccess, unless you a really careful about backing this up when you update core.

Of the two options, I would use the Redirect module. I would also think very carefully about committing to a multisite solution. They tend to create more problems than they solve.

2
  • thanks for the swift reply. I have the redirect module installed but hadn't really looked at it in detail - plus I thought Apache level redirects might be more efficient(?). I'll keep on researching multisite, but I'm moving against the idea - at least for the initial deployment. These sites have 10 years bespoke logic moved over to Drupal so there is plenty of potential to go wrong... Feb 21, 2014 at 15:29
  • @ChrisLeather Apache will be more efficient, but that means that someone needs to the edit the file, and how you don't add a syntax error and bork all of your sites for a while. With the Redirect module, you can have non-technical people manage everything. This works out fairly well for me.
    – mpdonadio
    Feb 21, 2014 at 15:32

Your Answer

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

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