Start Online Training

Get access to all our video classes and support. That's 1808 training sessions in Joomla, Drupal, WordPress, Coding and SEO.
Prices start only at only 25 USD per month

Testimonials

Testimonials OSTrainingI learn so much from you guys. I really appreciate your service!"

~ Emily

 

Start a FREE 7 day trial! Get training videos and books, plus expert support:  

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

How to hide /sites/default/files/ in URL? 11 months 4 weeks ago #69584

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: 11 months 4 weeks ago by steve.
Please become a member of OSTraining to reply to this post.

How to hide "/sites/default/files/&qu​ot; in URL? 11 months 4 weeks ago #69625

  • steve
  • steve's Avatar
  • OFFLINE
  • Posts: 5842
  • Thank you received: 262
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>
Ask. We'll help. It's as simple as that.

Follow us on Twitter - twitter.com/ostraining
Like us on Facebook - facebook.com/ostraining
Please become a member of OSTraining to reply to this post.

How to hide "/sites/default/files/&qu​ot; in URL? 11 months 4 weeks ago #69664

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? 11 months 4 weeks ago #69666

  • steve
  • steve's Avatar
  • OFFLINE
  • Posts: 5842
  • Thank you received: 262
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.
Ask. We'll help. It's as simple as that.

Follow us on Twitter - twitter.com/ostraining
Like us on Facebook - facebook.com/ostraining
Please become a member of OSTraining to reply to this post.

How to hide "/sites/default/files/&qu​ot; in URL? 11 months 4 weeks ago #69761

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? 11 months 4 weeks ago #69766

  • steve
  • steve's Avatar
  • OFFLINE
  • Posts: 5842
  • Thank you received: 262
You're welcome, jkrivanek

Let me know if you have any follow-up questions at all after trying that module.
Ask. We'll help. It's as simple as that.

Follow us on Twitter - twitter.com/ostraining
Like us on Facebook - facebook.com/ostraining
Please become a member of OSTraining to reply to this post.

 

Start a FREE 7 day trial! Get training videos and books, plus expert support: