Simple way to have a better files directory link in Drupal

I maintain a Drupal website with several hundred files in the /sites/default/files folder. It's a big mess - they're unsorted, many are no longer referred to, and so on. That's another topic.

I was wondering if there was a way to make future links nicer. People accessing the website or sharing links to files on our website don't want to type "sites/default" - that's stupid!

There is an option in Drupal config (Drupal 6: admin/settings/file-system; Drupal 7: admin/config/media/file-system) to change the default files directory, but I've never done that for a site so far so all of the current files would need to have all references updated to make that nicer. Maybe I'll do that if I make another Drupal site!

But here's one neat trick doctors don't want you to know: in the root directory of your Drupal install, execute "ln -s sites/default/files files". This creates a symbolic link to the files directory in the drupal root. Now if you upload a file called "runme.exe" to your Drupal files directory, the website will say it's accessible at

http://devinhoward.ca/sites/default/files/runme.exe

BUT you will be able to share out links (and maybe change code on the website so it *thinks* that's where the files live and communicates that to end users of the site) that look like

http://devinhoward.ca/files/runme.exe

It's a small thing, but it makes me feel better about foisting the links involved on non-technical users. Plus it's such a friendly solution that seems pretty robust.

Add new comment