Long URL's for Multisite files folder

public
group: Multisite
gtrusler - Fri, 2008-03-28 05:34

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

Private vs. Public files

BoatDaddy - Tue, 2008-04-08 23:30

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

weedoo12345's picture
weedoo12345 - Thu, 2008-04-24 20:08

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

yan - Fri, 2008-07-18 19:08

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).

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.

Could you give me a hint on how to do that?

Worked for me

ccalnan's picture
ccalnan - Mon, 2008-07-21 21:21

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

Boris Mann's picture
Boris Mann - Mon, 2008-07-21 21:32

...with both REQUEST_FILENAME and HTTP_HOST. See http://shiflett.org/blog/2006/mar/server-name-versus-http-host for some basic XSS examples.