Manolis
Manolis

Reputation: 891

Mask outgoing links

On a php web page, i'm displaying an html5 player which plays an mp3 track, and there's a download button next to that. I want to mask the download link only, so visitors will not be able to see the directory tree of my server (www.example.com/content/plugins/audio/downloads/test.mp3). I want to change the link to something more simple and smaller like (www.example.com/download/test.mp3) without changing the folders structure of my server.

I'm not sure if it is an .htaccess or PHP thing.

Thanks in advance.

Upvotes: 0

Views: 246

Answers (1)

knittl
knittl

Reputation: 265928

With .htaccess you would need the following rewrite rule:

$ pwd
/var/www
$ cat .htaccess
RewriteEngine on
RewriteRule ^/download/(.*\.mp3) /content/plugins/audio/downloads/$1 [NC]

It will match all http://yourdomain.com/download/….mp3 requests and redirect to http://yourdomain.com/content/plugins/audio/downloads/….mp3

If you want your .htaccess to work from inside a subdirectory, use RewriteBase:

$ cat subdirectory/.htaccess
RewriteEngine on
RewriteBase /subdirectory
RewriteRule ^download/(.*\.mp3) content/plugins/audio/downloads/$1 [NC]

i.e. http://yourdomain.com/subdirectory/download/….mp3 to http://yourdomain.com/subdirectory/content/plugins/audio/downloads/….mp3

Upvotes: 2

Related Questions