Hi, I'm using filefield paths to try and create a decent way of managing my files and while that's working fine, the URL is still a bit of an issue. I wonder if it's possible to hide the "sites/default/files" part of the URL so you go from:

sitename.com/sites/default/files/nodetitle/file.jpg

TO

sitename.com/nodetitle/file.jpg

Thanks for reading.

Comments

ytin’s picture

Have you looked at the PathAuto module? http://drupal.org/project/pathauto

clintu’s picture

barrett’s picture

I'd like to know how to do that too. I would think path aliasing, but there isn't (that I can see) an auto alias setting for it.

cog.rusty’s picture

The simplest way is to specify "files" and not "sites/all/files" as your files directory in admin/settings/file system, and
- either actually store them in a /files directory under drupal (this is what I do)
- or create a sites/all/files directory and then create a "files" symlink under drupal or an apache alias, pointing there.

That is fine for a new site but could cause broken links if you already have uploaded files, and you would need to do some path repairs in the database and clear the cache.

A less clean method would be to come up with some complicated .htaccess rewrite conditions to find file requests ending in ".jpg", and if the file doesn't exist and a file with same name exists under sites/all/files to redirect there. Then you would be able to enter shorter file links in the content, relative to the current path, but of course the user would end up seeing a sites/all/files path after the rewrite. Also, wysiwyg editors etc which place links in the content would need to be intentionally misconfigured to produce the node-relative paths. Too messy.

About aliases, Drupal can't create aliases for real file links, only for Drupal's own virtual paths.

barrett’s picture

For multi-site installations, using a single file repository isn't an ideal solution. Site A's files shouldn't be stored in the same location as Site B's. Sym-linking would work but would require multiple links. It seems like there should be a way to have Drupal handle serving files from the sites/.../files directories in a manner that is more transparent.

cog.rusty’s picture

Actually I use /files/site1-short-nickname, /files/site2-short-nickname. This is an additional benefit, because if I used /sites/example.com/files in Drupal 6 I wouldn't be able to move the site easily to/from a development server with a different domain name (for example localserver). This is going to be solved in Drupal 7 (see http://drupal.org/node/231298).

I forgot to mention the "private downloads" method (in admin/settings/file-system) which always gives you virtual file links like "system/files/filename", no matter where you have stored the files. This is pretty transparent, but it has a performance penalty for processing the paths and reading/serving the files.

barrett’s picture

Good to know about the D7 change. Thanks for that link.

So private downloads will handle the multi-site use case also? As you can tell, I haven't done anything with it.

cog.rusty’s picture

Sure, private downloads always use "system/files/" paths and transparently serve each site's files from wherever they really are (even if they are outside the web root and don't have an URL).

They don't alias the URL. They read the file from disk and create a virtual URL.

pobster’s picture

http://drupal.org/node/53705

Create a 'files' directory in your Drupal root and place this .htaccess file in it;

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /sites/%{HTTP_HOST}/files/$1 [L]

Pretty much everything you'll ever need is in the Drupal handbook you know...

Pobster

highvoltage’s picture

"Pretty much everything you'll ever need is in the Drupal handbook you know..."

Maybe but it's still hard as hell to find where in my experience.

deciphered’s picture

Hi highvoltage,

There's an addon module I wrote for FileField Paths called File Aliases, it was created for that exact purpose.

Simply define your File Alias on the FileFile Paths settings area, and check the box to show the alias.

It's still in a very early state and has a known issue with Views, but testing would certainly help it improve.

Cheers,
Deciphered.

dishwalla’s picture

I've installed FileField and File Aliases modules, but I don't see where I should edit my file paths. For example, I don't see an 'Upload Path Settings' options under 'Workflow settings' per the readme.
At any rate, most of my pdf files that I link to in my site are inline in my page content. 'I think' I'm usting fckeditor's wysiwyg to upload the pdf files that I'm linking to inline.

Recap: No idea how to incorporate file aliasing.... I'm probably missing something.

vm’s picture

workflow settings where?

ensure you are editing the content type, and then the file field one which you want the filefield_paths to take effect.

dishwalla’s picture

If I edit the content-type "page" for example, there is a "workflow settings" option (which, according to the module readme would indicate where to edit the alias?- the readme is a bit thin)

Regardless, I don't want to edit the alias for any 'field' in a content-type, but rather just any file that I upload through fckeditor or wherever.

I want all of my pdfs in /sites/default/files/file/ to be aliased to just /file (as this original post suggests) but I don't see anywhere this aliasing module provided an option to change that (not saying that it doesn't, I just can't find it)

vm’s picture

nono. not by editing a content type workflow settings. You would have to edit the actual filefield path (if using that module) or If using filefield_aliases as the comment above is, then you need to check the settings for that specific module or see if they are listed in administer -> url aliases

deciphered’s picture

Dishwalla,

If you would like support on how to setup the File Aliases module, the best solution would be to open a Support Request issue in the File Aliases issue tracker: http://drupal.org/project/issues/file_aliases

Cheers,
Deciphered.

fab01’s picture

Hi,
I tried your module but it throw the following error (CLI) during installation procedure via drush:

"Cannot add field filefield_paths.filealias: table doesn't exist."

I tried uninstalling and reinstalling both 'file field paths' and 'file aliases' Modules on two different drupal installations.
I always get the same result.

The install function within .install tries in fact to alter filefield_paths table which actually does not exist (as clearly reported on the error message above).

vm’s picture

issues such as the above should be generated as bug reports in the issue queue of the module throwing the error.

fab01’s picture

Ok, I have found a couple patches to fix the problem but since this is not the right place to discuss about this (did I correctly understood?) I will maybe report them on some more appropriate forum.
Thank you anyway.

clintu’s picture

In some scenarios hook "hook_file_url_alter(&$uri)" will help