0

I have a rewrite map associating pictures hash to the real path (to be kept secret) of the picture. With a single rewrite rule I can give back the picture with the hash as the url, that's fine.

However this is the path that I would like to keep secret, not the picture name. Even if the name is not secret, I don't want users to directly access with server/image_name.jpg I thus think that providing the filename in the content-disposition header is OK.

I came up with this:

RewriteMap redirector txt:C:/Apache24/url-mapping.txt
RewriteEngine On
RewriteRule ^/i/(.*)$ ${redirector:$1} [E=filename:${redirector:$1}]
Header set "Content-disposition" "attachment; filename=%{filename}e"

But the mapping is of this shape:

fa54e01623f625b1a6160fa0fee24112 /images/apath/to/picturename.png

And the current configuration takes the whole path, not the last part.

So my questions are:

  1. is there another way to achieve what I want to do?
  2. with the Content-disposition solution, how and where can I take a part of my variable filename to really have the filename?

Thanks!

1 Answers1

0

I came up with the following solution (using a dummy rewrite):

RewriteMap redirector txt:C:/Apache24/url-mapping.txt
RewriteEngine On
RewriteRule ^/i/(.*)$ ${redirector:$1} [E=path:${redirector:$1}]

RewriteCond %{ENV:path} .*images.*/(.*)
RewriteRule .* - [E=filename:%1]
Header set "Content-disposition" "attachment; filename=%{filename}e"

with the following kind of rules in url-mapping.txt:

fa54e01623f625b1a6160fa0fee24112 /images/myimage.png