This issue:
#580058: allow files to be referenced only with /files/ (instead of /sites/fqdn/files)
says that it's possible to use URL rewriting so that sitename is no longer in the url, e. g. "example.com/files/attachment.wtf" instead of "example.com/sites/exmaple.com/files/attachment.wtf".

This would immediately resolve the development→production migration pain for me.

But i found no documentation on how to enable and use this feature.

So... How do i do that? Which files to modify, etc?

Also, will it work okay for domain aliases? This is very important.

Thank you!

Comments

lolmaus’s picture

Title: URL rewriting? » How do i enable URL rewriting? I want "example.com/files/file.wtf" instead of "example.com/sites/exmaple.com/files/file.wtf".
lolmaus’s picture

Title: How do i enable URL rewriting? I want "example.com/files/file.wtf" instead of "example.com/sites/exmaple.com/files/file.wtf". » I have "sites/exmaple.com/files/file.wtf" URLs rewritten to "files/file.wtf", how can i make Drupal serve files with short URLs?

Okay, i found this chapter of Aegir documentation: Injecting into site vhosts.

I've created a file /var/aegir/.drush/filesrewrite.drush.inc with the following content:

<?php
        function filesrewrite_provision_apache_vhost_config($uri, $data) {
                return 'RewriteRule ^files/(.*)$ /sites/%{HTTP_HOST}/files/$1 [L]';
        }
?>

It works, the files are now accessible via "example.com/files/file.wtf".

The question is: is there a way to make Drupal serve files with such URLs?

One may attach a file to a post and paste the URL to the file into the post's body. When i stage the site, this URL will break. So i wonder whether Drupal can provide short URLs in the first place?

omega8cc’s picture

Project: Hostmaster (Aegir) » Provision
Status: Active » Closed (works as designed)

It is already built-in feature/rewrite: http://drupalcode.org/project/provision.git/blob/refs/heads/6.x-1.x:/htt...

You don't need to add anything extra to use short URL.

However, using short URLs in Drupal natively/automatically is not possible. You can use them when you enter/use the URL manually.

omega8cc’s picture

Also, Aegir rewrites URLs also in the content, and at least in the BOA fork also for Drupal 7 sites: http://drupalcode.org/sandbox/omega8cc/1074910.git/blob/HEAD:/platform/d...

lolmaus’s picture

Also, Aegir rewrites URLs also in the content, and at least in the BOA fork also for Drupal 7 sites: http://drupalcode.org/sandbox/omega8cc/1074910.git/blob/HEAD:/platform/d...

I've got Aegir installed from Debian packages. I've just tried renaming a site, and its content pointing to an actual attachment (e. g. <img src="http://old.example.com/sites/old.example.com/files/ming-face.png" alt="test"/>) has not been fixed. :(

Is there a way i can enable content rewriting as you mention above?

Before Aegir, i used to use symlinks to resolve the issue. It was very simple. But on Aegir, using symlinks in place of the sites/example.com/files breaks migrations.

I find it a major flaw of D7. Drupal.org itself has this problem hacked somehow, but all other Drupal-powered sites have to face this issue. :( Before asking, i've googled extensively and i found a lot of people struggling with the issue. I just don't understand how staging sites can be possible with this issue existing.

So... is your suggestion available for vanilla Aegir from Debian packages?

lolmaus’s picture

omega8cc’s picture

You just need to replace your /var/aegir/.drush/provision/platform/drupal/deploy_7.inc file with BOA version.

It was already submitted for review here, but core devs decided to refuse to accept the request, so it is included only in BOA.

lolmaus’s picture

Thank you, omega8cc, i'll give it a try. You're very kind and helpful.

busla’s picture

@omega8cc: Do I understand you correctly that BOA uses the rewrite by default?

My image urls are: "mysite.com/sites/mysite.com/files/images/myimage.jpg"

busla’s picture

Issue summary: View changes
Status: Closed (works as designed) » Active

I hope it´s ok if I re-open this issue. Please correct my if I´m wrong.

busla’s picture

Version: 6.x-1.9 » 6.x-2.0

changing version

omega8cc’s picture

Status: Active » Closed (works as designed)

Aegir (and BOA) does the rewrite for /files/* but it doesn't modify native URLs generated by Drupal which have to use multisite specific paths. The rewrite is useful only to reference files in e-mails, in the content etc. if you want the short URL, of course.

busla’s picture

Ok, so for images on my server, that are controlled by file_entity, I would need to use a path alias to change this?

omega8cc’s picture

No. Any aliasing inside Drupal works only for dynamically generated pages, not for files. Also, I don't think you can change that anyway. It is hardcoded on the settings.php level to satisfy Drupal core behaviour. I mean, you shouldn't mess with Drupal core to modify the paths it expects by default.