1

I have an url www.example.com/english/magazine-one/offline/download.pdf, where I want to access the download.pdf but shows magazine-one.pdf (the magazine folder name) instead without actually renaming the PDF file.

So I have managed to come up with this in my htaccess

RewriteEngine On
RewriteRule ^(.*)offline/magazine-one.pdf$ $1offline/download.pdf [L]

This allows me to mask the URL and access the pdf directly from magazine-one.pdf. However, when I access download.pdf the url still does not change and point to magazine-one.pdf.

Would be great if someone can throw some ideas in.

Abhishek Gurjar
  • 7,426
  • 10
  • 37
  • 45
lazygin001
  • 11
  • 1
  • So you want an _external_ redirect then when `download.pdf` was requested, to the faked URL(?). What exact problem do you have with implementing it? – CBroe Jul 12 '18 at 12:51
  • Wouldn't what you're asking for result in an infinite loop? You're saying that you want magazine-one.pdf to give you download.pdf, but that download.pdf should send you to magazine-one.pdf. – Patrick Q Jul 12 '18 at 12:57
  • @CBroe Yes - so if I go on to download.pdf, the URL in my browser needs to display magazine-one.pdf instead. Essentially it is a fake URL but displays the content of download.pdf. Currently I am having trouble figuring out how to redirect download.pdf when magazine.pdf is just a fake file. – lazygin001 Jul 12 '18 at 13:05
  • @PatrickQ You are right, the page was giving me error with too many redirections. Do you have other ideas of how to go about this? – lazygin001 Jul 12 '18 at 13:07
  • You need to differentiate between what the current internal request is, and what was originally requested by the client. You only rewrite externally from `download.pdf` to `magazine.pdf`, if the _original_ request by the client was for the former. Basically a RewriteCond that checks the THE_REQUEST variable, similar to https://stackoverflow.com/a/12238553/1427878 – CBroe Jul 12 '18 at 13:46

0 Answers0