All media on my website is placed in the folder 'images'. All PDFs are placed in 'images/PDFs'. Now I would like to rewrite the URL such that it looks like the PDFs are in the folder 'downloads', which they're not.


Original URL: 'mywebsite.com/images/PDFs/NAMEPDF.pdf'

Rewritten URL: 'mywebsite.com/downloads/PDFs/NAMEPDF.pdf'

I tried it with MOD rewrite, but this doesn't work:

RewriteCond %{THE_REQUEST} ^GET\ /images/
RewriteRule ^images/(.*) /downloads/$1 [L,R]

Does somebody knows how to do this?


I would do this instead:

RewriteCond %{REQUEST_URI} /images/
RewriteRule ^images/(.*) /downloads/$1 [L,R]

I think REQUEST_URI will be a better check than THE_REQUEST for you.

Reference: http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html


Just to make sure this is understood correctly, the above allows you to use the url with 'images' in it, but to put all of the files in the downloads folder on your server.

If you want it to "look" like the PDFs are in the downloads folder but actually have them in the images folder, you would need to switch the usage of each of these words.

The rewrite rules don't change the url on your site; they change how the server understands the url.

  • Thank you David! You're answer is clear. Unfortunately I'm trying to do the wrong thing, as I try to change the URL. Eventually I solved it by finding an editor that supported seperate directories for files and images, namely JCK editor. Now I upload the files in a seperate directory and this trick is not necessary anymore. – Nick Sep 13 '14 at 11:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.