By venkat-rk on
In a multi-site install, files take the path sites/domain.com/files/filename.
Can anyone advise about the code to put in the .htaccess file at the root of the drupal install that will change this to domain.com/files/filename?
Thanks in advance.
Comments
Do you mean
Do you mean http://domain.com/files/filename without any differentiation in the path? That would be interesting...
That's right. And, I want to
That's right. And, I want to be able to do this without mucking around with the image paths. In other words, a file or image I upload will always have the path sites/domain.com/files/filename, but will be seamlessly rewritten to http://domain.com/files/filename using .htaccess.
It would be pretty odd to have 'sites' in the url, in my opinion.
----
Previously user Ramdak.
Don't do that
The files are not in the "sites" directory by default; you put them there. Go to admin >> site configuration >> file settings and change the path.
I put all mine in files/somename, where somename is an abbreviation of the sitename. I hate coding very long paths in IMG and A tags.
Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database
NancyDru
I agree with this, since
I agree with this, since putting the files under /sites/example.com/files has no real benefit. It even makes things worse by making the file/image paths depend on the domain name. There is a workaround for this:
- You put the files under /sites/example.com/files
- You create "files/somename" symlinks using
ln -s /[blah]/sites/example.com/files /[blah]/files/somename- You tell Drupal that your files are in "files/somename", and Drupal follows the symlink and finds them.
Personally I think this trick is a bit silly. What you gain by having all your files cleanly under /sites (for one-place-backups etc) you lose it again by having to maintain the symlinks... So I just do the same as you.
But I was wondering if it is possible at all to get rid of "somename" completely, using some .htaccess trickery where each http://domain.com/files leads elsewhere for each site. Presently I don't see how...
Thanks, nancy and cog.rusty.
Thanks, nancy and cog.rusty. But, I have read comments elsewhere in favour of having a separate files directory for each domain and even the multi-site handbook seems to recommend that:
http://drupal.org/node/53705
----
Previously user Ramdak.
I do
I do have a separate files directory for each domain, but it's in files, not sites.
Compare
<img src="/sites/an-extremely-verbose-domain-name.com/files/picture.gif">to<img src="/files/xvdn/picture.gif". And believe me, some of my domains have very long names and I am a lazy webmistress.I've even considered changing the "files" directory name to just "f". ;-)
Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database
NancyDru
I think it is not just
I think it is not just verbose, it is wrong. It introduces a dependency on your current domain name inside all file paths, making it hard, for example, to work with a development version of the site, either local or on the server.
Symbolic names for the sites are much more convenient.
nancyw and cog.rusty- you
nancyw and cog.rusty- you experts, this is water above my head :(
Does this mean that:
1.) the handbook page is wrong ?
2.) that symlinking is better than putting a separate file for each site in the /files folder?
3.) Or, is putting it in /files the right thing?
----
Previously user Ramdak.
Here is what this... expert
Here is what this... expert thinks.
Is the handbook page wrong?
It works, but as a "best practice" I believe it is wrong. The method suggested ("sites/example.com/files") has one minor advantage and several important disadvantages, as I will explain.
The handbook page was written by someone like you and me who though that was a good idea. Personally I have a problem going and changing something which someone else wrote without convincing that someone first (probably this is the reason I never use wikis).
A couple of first remarks:
- The sites/example.com directory does treat modules and themes in a special way but it does absolutely nothing for files. So, it is a pretty arbitrary decision of convenience to place the files there.
- The default in a Drupal installation is "files", while it would not have been hard for Drupal to get the directory name of your settings.php and place the suggested default files directory there if the core committers were convinced.
A problem with *any* default is that, when it comes to multisites, the user needs to foresee future needs and plan for them. If after a while you have several file links in nodes, containing "/sites/example.com/files/filename" or "/sites/default/files/filename" and you decide a change you will have to do database surgery.
Perhaps it would be a good idea to have a "site alias" string in core, but I am getting ahead of myself here.
Is the symlinking better than putting a separate file for each site in the /files folder? Or, is putting it in /files the right thing?
1. Using just "files".
- Neither this nor "sites/default/files" is any good for subdomains.
2. Using "files/site_alias" vs "sites/example.com/files"
pros:
- Simpler and more reasonable file links of the form "/files/site_alias/filename" vs "/sites/example.com/files/filename" (both when entering a link into the content and when accessing a file)
- File links independent of the actual domain name. You just have to use the same "site_alias" when you change domain and all your file links will still work. With file links containing "example.com", you can't change it. Your domain name is what it is, and you would have to do database surgery whenever you want to change domain or maintain a development site or a mirror site.
cons:
- Two places to remember to backup (/sites and /files). Notice that the "/sites/example.com/files" method has no other advantage whatsoever except single-point-backup".
3. Using "symbolic links" in Linux or "junctions" in Windows
This is the method which Boris Mann suggested in that um.. "experts excange" in the mailing list, and which I described in my second post in this thread.
It is a very versatile method, which allows you to use file links of the form "files/site_alias" everywhere, while actually you have your files stored in "sites/example.com/files". You have all the advantages and none of the disadvantages of the above methods, except one: You have to maintain the symlinks or junctions and modify them whenever you move the site or make any changes to domains. (This, in my opinion, is harder than having to remember to backup two directories, "sites" and "files", but you may have other reasons to do it).
Essentially you start with the "files/site_alias" method, you set up everything, and then you move the files to "sites/example.com/files" or wherever you want, and you replace the old "files/site_alias" directory with a symlink which leads to where you put the files.
What I believe is that the "sites/example.com/files" method is only good if you are going to use symlinks as well. Otherwise it is nothing but trouble. So, it is always best to set it up with "files/site_alias", since this is also the way to later store the files in "sites/example.com/files" and use symlinks.
Hi cog.rusty, I can't thank
Hi cog.rusty,
I can't thank you enough for taking the time and trouble to educate a fellow drupal user on this intricate subject. It is much more clear to me now, although I am still trying to digest all the info. Much, much appreciated.
And, since I have edit privileges for book pages, I will put this into the relevant book page and put it up for a vote by raising an issue against the documentation project. It would seem rather high-handed if I edited the page straight away, but much less intrusive if it went through a process of approval.
----
Previously user Ramdak.
I cant agree with you more!
I cant agree with you more! I have been keeping my files in a files/site_alias directory instead of a sites/domain.com/files directory. I do not find it inconvenient to to have to backup two folders when moving or updating my sites. Indeed in my particular case it was a plus. I have gigabytes of files in the files/site_alias folder and when I recently moved my sites to another server I opted to move my sites directory first (which took seconds), have the sites up to address any server side issues such as differences in PHP versions or settings, while I wait the hours required to upload the huge files directory.
Moreover there is one case where I have two different domains for one site. I did not have to duplicate the files directory or make any symlink
Well... I haven't been so
Well... I haven't been so convincing, after all. Drupal 6 has set the default files directory to sites/default/files.
No big problem there, since the path doesn't contain a domain name. Except if people decide "by analogy" to do the same for their multisites, making them unmovable.
Subscribe
CogRusty is Drupal's foremost thinker on this topic, as far as Agaric is concerned.
~ben
benjamin, Agaric
Hmm...
It's good to know that I came up with the same solution as "Drupal's foremost thinker" on my own.
Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database
NancyDru
Heh, of course
Heh, of course, I and Boris Mann, to be fair, but he does multisites for a living.
So, puzzle solvers do get an audience if they post to the mailing lists from time to time ;-)