[htmuoljh]
You can build great websites. We can help! Join today and get access to 2620 training videos: Start a free trial!

Get support. At OSTraining, you'll never get stuck. Our team of experts are always here to help

TOPIC: How to hide /sites/default/files/ in URL?

How to hide /sites/default/files/ in URL? 2 years 9 months ago #69584

  • jkrivanek
  • jkrivanek's Avatar
  • OFFLINE
  • Support Member
  • Posts: 5
My client uploaded all the files (pdf, images) into the <ROOT>/sites/default/files/subfolder/ directories.
Once the file was uploaded, the reference URL will point to, eg.:
www.example.com/sites/default/files/subfolder/XYZ.pdf

Is there a way to hide the folders structure: /sites/default/files/ in URL? So that when user click on the URL link, www.example.com/sites/default/files/subfolder/XYZ.pdf, the URL will automatically redirect to www.example.com/subfolder/XYZ.pdf ?

Here is the dilemma:
1. The redirect could be set up in .htaccess but of course the redirect will give the "page URL not found" error.
2. If simply setup "Rewrite Rule" in .htaccess, the server will be able to open www.example.com/subfolder/XYZ.pdf because it actually looks for "/sites/default/files/subfolder/" as the Rewrite Rule told it to.

The problem is that both "Redirect" and "Rewrite" could only work partially, when putting together they will conflict each other. So how to hide "/sites/default/files/" in URL?
I think that this is supposedly a common practice for websites to hide the real pathway to private files. Could you provide some help? Thanks.
Last Edit: 2 years 9 months ago by steve.
Please become a member of
OSTraining to reply to this post.

How to hide "/sites/default/files/&qu​ot; in URL? 2 years 9 months ago #69625

  • steve
  • steve's Avatar
  • NOW ONLINE
  • Super User
    Pro Member
  • Posts: 10721
  • Thank you received: 359
Hi jkrivanek

To some extent, I believe you're over-complicating this.

If you have your files in /sites/default/files/ then they're not private at all. They can be accessed by anyone and that's even easier if they know you're using Drupal, because they can guess the path.

To solve this, Drupal actually has a private files option in Configuration > Media > File system > Private file system path. The best solution in there is to set a location that is above the root. It will look like this /downloads/<ROOT>
Please become a member of
OSTraining to reply to this post.

How to hide "/sites/default/files/&qu​ot; in URL? 2 years 9 months ago #69664

  • jkrivanek
  • jkrivanek's Avatar
  • OFFLINE
  • Support Member
  • Posts: 5
Hi Steve,

Sorry I probably said something misleading. The files are not private files. They are public files for which we want a shortened, marketing friendly url.

For example, when user click on URL www.example.com/sites/default/files/subfolder/XYZ.pdf,
We want it redirect to a more marketing friendly url:
www.example.com/subfolder/XYZ.pdf

However, XYZ.pdf file is actually stored under: <ROOT>/sites/default/files/subfolder/XYZ.pdf
Please become a member of
OSTraining to reply to this post.

How to hide "/sites/default/files/&qu​ot; in URL? 2 years 9 months ago #69666

  • steve
  • steve's Avatar
  • NOW ONLINE
  • Super User
    Pro Member
  • Posts: 10721
  • Thank you received: 359
Thanks jkrivanek, that makes sense.

There used to be a module for doing this, but it's only Drupal 6 I'm afraid: drupal.org/project/shorturl

There is this for Drupal 7: drupal.org/project/shorten but you'll need to connect it with another non-Drupa service.
Please become a member of
OSTraining to reply to this post.

How to hide "/sites/default/files/&qu​ot; in URL? 2 years 9 months ago #69761

  • jkrivanek
  • jkrivanek's Avatar
  • OFFLINE
  • Support Member
  • Posts: 5
Hi Steve,

I appreciate your prompt reply, will see whether "shorten" is the module. Thanks for helping.
Please become a member of
OSTraining to reply to this post.

How to hide "/sites/default/files/&qu​ot; in URL? 2 years 9 months ago #69766

  • steve
  • steve's Avatar
  • NOW ONLINE
  • Super User
    Pro Member
  • Posts: 10721
  • Thank you received: 359
You're welcome, jkrivanek

Let me know if you have any follow-up questions at all after trying that module.
Please become a member of
OSTraining to reply to this post.
You can build great websites. We can help! Join today and get access to 2620 training videos: Start a free trial!

Arvixe

Welcome to training with a smile :) Created by friendly people all across North, Central and South America.