We are adding the following rewrite rule to drupal's .htaccess here in the Aegir project:

  RewriteRule ^files/(.*)$ /sites/%{HTTP_HOST}/files/$1 [L]

There are multiple reasons for this:

1. renaming sites is easier: instead of having to go through the whole body and teaser columns to fix the URLs to files, they remain consistent when we migrate sites between dev/qa/live environments.
2. it works and is backward-compatible: this works transparently and the old URLs are still valid
3. it looks nicer: URLs like http://example.com/sites/default/files/mysong.mp3 or http://example.com/sites/example.com/files/mysong.mp3 are much uglier than http://example.com/files/mysong.mp3.
4. it takes less bandwidth: this is arguably negligible, but sites/fqdn/ is at least 10 bytes more per URL you put in your page, more if the URL is longer.
5. it's more elegant: URIs are there for a reason, and they have a meaning: there's no reason why the FQDN should be embedded twice in a URL.

But the base idea is to be able to rename sites easily and transparently without breaking URLs all the time. This would be immensely useful for development teams doing dev/qa/staging work, multisite environments and so on.

There are two parts in this issue:

1. have a files -> sites/fqdn rewrite rule
2. make Drupal generate URLs pointing to files/ instead of sites/fqdn

I understand that the new stream wrapper work may predate some of the work here, but I'm looking at a way to have proper URLs by default, for the "normal" multi-site hosting use case and not the CDN / Youtube funky "your files are over there now" use case.

Comments

dave reid’s picture

Unfortunately this wouldn't work if your site's folder is not a hostname (e.g. 'default') or would require you to use sites.php for every domain.

Status: Active » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.