2012-01-28 61 views
0

在一个php的网页上,我显示一个播放mp3曲目的html5播放器,并且旁边有一个下载按钮。我只想屏蔽下载链接,因此访问者将无法看到我的服务器的目录树(www.example.com/content/plugins/audio/downloads/test.mp3)。我想将链接更改为更简单更小的链接,例如(www.example.com/download/test.mp3),而不更改服务器的文件夹结构。Mask输出链接

我不确定它是.htaccess还是PHP的东西。

在此先感谢。

回答

2

随着.htaccess你会需要以下重写规则:

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

它会匹配所有http://yourdomain.com/download/….mp3请求,如果你希望你的.htaccess从一个子目录内工作重定向到http://yourdomain.com/content/plugins/audio/downloads/….mp3

,使用RewriteBase

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

http://yourdomain.com/subdirectory/download/….mp3http://yourdomain.com/subdirectory/content/plugins/audio/downloads/….mp3

+0

所以,如果我把我的网站上的链接像(www.example.com/download/test.mp3),它会重定向到(www.example.com/content/plugins/audio/downloads/test.mp3) ? – Manolis 2012-01-28 15:12:28

+0

@Manolis:apache会重写原始URL并返回content/plugins/...文件。 – knittl 2012-01-28 15:14:38

+0

下载链接如下所示:'' 所以mp3文件路径是$ audio。有没有更快的方法来改变它的出现方式?我不确定你是否理解我的意思,也许是另一种方式而不是htaccess?谢谢。 – Manolis 2012-01-28 15:27:18