2012-01-28 78 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