I have set up my first multisite installation and I have a question. I have parked a domain using CPanel onto my main domain and I have directories set up for each site in the sites folder. Here is what my sites directory looks like for the 2 domains:
sites/domain1.com/files
sites/domain1.com/modules
sites/domain1.com/templates
sites/domain1.com/tmp
sites/domain1.com/settings.php
sites/domain2.com/files
sites/domain2.com/modules
sites/domain2.com/templates
sites/domain2.com/tmp
sites/domain2.com/settings.php
Everything seems to be working fine. However, the only issue I'm having is the length of the URL's for anything in the files directory. Instead of a URL that I currently have like this:
www.domain1.com/sites/domain1.com/files/image.jpg
I'd prefer this:
www.domain1.com/files/image.jpg
I found the following information in the handbook here:
http://drupal.org/node/53705
Files Directory
The following user-submitted code may be useful in redirecting URLs for the /files directory to the /sites/example.com/files directory. The following code is added to the [drupal_root]/files/.htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /sites/%{HTTP_HOST}/files/$1 [L]
Unfortunately, it doesn't appear to be working.
I'm using also using the XMLsitemap module and it needs separate files directories for each site. Does anyone have any suggestions for shorter URL's for the files directories in each site?
Thanks,
Graydon
Comments
Private vs. Public files
If you have your site set to Public files the above idea should work. The concept seems valid, might need some tweaking of the of the .htaccess rules and play with the placement in .htaccess compared to other rules.
If your sites are set to Private files, then the request is being processed by Drupal (not the web server) so the above idea will not work. Drupal needs to apply security checks before transferrring the file.
In this case you can create a custom module that processes the "/files" path and translates the path to the real file path in the 'sites" directory and then uses the standard Drupal fiel processing.
Same problem here
I've been wanting to do the same thing, I understand everything from the htaccess tweak which let me point files to the files and the files themselves avec loaded from the sites/www.whatever.com/files. One things that just stops me totally is that I'm wondering what information I should enter in the file system settings from the admin, should I enter "files" or "sites/www.whatever.com/files"... If the good answer is the second one, it means each time I want to print an image on a page I should use regex to replace the additional part to get a simplified "files/xxx.xxx" path.
Anyone got an answer with this one please ?
Olivier Lemire
I'm having the same problem
I'm having the same problem and I'm looking for a nice way to get better URLs and seperate file directories. The .htaccess part works fine for me but everything that is processed by Drupal internally isn't affected by the rewrite (in my case: uploading files and manipulating them with imagecache).
Could you give me a hint on how to do that?
Worked for me
Hi, I just tried the option to add the following code to the .htaccess file.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /sites/%{HTTP_HOST}/files/$1 [L]
It worked, but only after I created a "files" folder in the drupal root folder, where index.php, cron.php, install.php etc. live. Then chmod to 777 and add the .htaccess file in that folder. It worked like a charm.
Be careful
...with both REQUEST_FILENAME and HTTP_HOST. See http://shiflett.org/blog/2006/mar/server-name-versus-http-host for some basic XSS examples.
Is this something to be
Is this something to be concerned about in this scenario though?
That's brilliant. Just what I
That's brilliant. Just what I needed.
Success?
Did you find a solution for this problem? It SEEMS like it wouldn't be such a big problem. Any insight would be greatly appreciated.
Question
This doesn't seem to work for uploaded files in Drupal and a file browser like CKFinder or IMCE. You have to point the Drupal file system at /files/, and then files are actually uploaded to that folder.
Anyone found a solution to this?
rbp - you could investigate
rbp - you could investigate symlinks for this, but you'd still need something to identify them uniquely from site to site. I don't think that any of these recommendations are good in the long term, as none of the paths are concrete.
FWIW, I've managed several multi-site setups and have learned to only use them when the sites are in the same general realm, i.e. www.example.com, dev.example.com, etc. In these cases I can either use the same files directory (/files/ for all domains) or something that's descriptive instead of obtrusive, like /files/dev/ and /files/.
I don't have a shared host, I
I don't have a shared host, I have full access to the apache configs, so I do this using aliases in the apache config. It works nicely.
Alias /subsite/files [path]
Alias /files [path]
or...
Alis /files/subsite [path]
Alias /files [path]
This won't work in htaccess.
I also use CKFinder and the CKEditor module which lets me define the path for files it inserts into img tags.
This also works well. This does not solve the issue with getting everything else in Drupal to use the paths, though. For things like image_cache I still get the long urls.
You may want to try to use
You may want to try to use hook_file_url_alter():
<?php/**
* Implements hook_file_url_alter().
*
* Replaces /sites/domain.house.gov/files with /files
*/
function MYMODULE_file_url_alter(&$uri) {
$scheme = file_uri_scheme($uri);
if ($scheme == 'public') {
$uri = 'files/' . substr($uri, 9);
}
}
?>
First rule of multisite: All
First rule of multisite: All domains point to the root of the Drupal installation, not any subdirectory.
Second rule of multisite: If you are using aliases, links, or .htaccess hacks, then you're doing it wrong.
Sorry, but there are many
Sorry, but there are many ways to handle a multisite config, depending on the given circumstances. If you think certain solutions are without merit, please provide some reasons why.
Well, it's stated very
Well, it's stated very black-and-whiteishly, but I agree - if you're implementing multi-site on a Drupal installation correctly, aliases/symlinks or .htaccess hacks on the live server should not be necessary, so if you ever find yourself about to use them, you need to stop and consider what you might be doing wrong.
That being said, I myself do use similar trickery on my local machine for development. Since my site directories will use the actual domain name of the site, such as
raygunrobot.com, they won't be "recognized" if I try to access them using a local testing domain such asraygunrobot.test, so I create araygunrobot.testsymlink that points to theraygunrobot.comdirectory. This isn't something I do on the live server, though.I think you are making an
I think you are making an assumption that the setup is only sub-domain based. If you are using sub-directory based sites, you will need some sort of linking or aliasing. You may also need aliases, symlinks, or .htaccess "hacks" to handle something like the original post; wanting to mask a directory path. Also, if you are on a shared host, your only option may be to get creative with the .htaccess file, as you won't have access to server level files. The point being that you may have to do things differently based on given circumstances, and none of is "wrong" on a live server, if you know why you are doing it and it is your best option.
Subdirectory-based subsites?
Subdirectory-based subsites? So like http://example.com/foo, http://example.com/bar, and http://example.com/baz are all different subsites on the same Drupal installation?
You're right, I didn't expect that. On the other hand, I'm also not sure why someone would desire a configuration like that. Care to elaborate?
There are a lot of reason to
There are a lot of reason to have subdirectory sites. For one, there is less network configuration involved, since you don't need to setup a sub-domain. Also, it allows the for the appearance of one site, even if they are separate. This is good if you are dealing with an organization that needs separate sites, maybe mimicking departments, but want the appearance of one. example.com is one site, but example.com/billing and example.com/hr are actually different sites.
I've also done this in cases where one section of a site is immensely complicated, and I don't want that bleeding over into the other areas of the website. I separate it into its own site. example.com is simple and requires no contrib modules, but example.com/thisotherarea has a thousand modules, custom code, is a huge performance drain, etc. Keeping them separate makes it easier to do things without compromising the rest of the site.
Your 2nd proclamation is
Your 2nd proclamation is false. Multisite hosting is greatly simplified by the .htaccess "hack" in the root Drupal files directory because the stored path URLs are reduced to simply /files/ instead of /sites/site.example.com/files/ which makes migrating sites much easier. Anyone with experience in helping people migrate Drupal sites from one URL to another (dev.example.com to www.example.com) will greatly appreciate the simplicity inherited by using this "hack"
Does anyone have a similar "hack" for lighttpd?
Had same issue. Don't know
Had same issue. Don't know why it was only with one of three hosting companies I use.
The solution I found may lack finesse, but simply adding a redirect to the parked domain so it points to domain1.com was what worked. Go figure.