Mod_rewrite will help change URI-based Content-disposition

I have a catalog of mp3 files that want to be able to serve them inline or provide the user with the ability to download based on the request URI.

/media/file1.mp3 - in this case, I just want to serve the file and let the browser play it.

/media/download/file1.mp3 - in this case, I want the user to easily upload the file.

I was able to accomplish this with mod_rewrite and php (using the header () and readfile () function), but I would rather do it all with mod_rewrite, mod_header, etc., if possible.

+3
source share
2 answers

mod_rewrite , Content-Disposition. Content-Type:

RewriteRule ^media/[^/]+\.mp3$ - [L,T=audio/mpeg]
RewriteRule ^media/download/[^/]+$ - [L,T=application/octet-stream]

mod_headers + mod_setenvif:

SetEnvIf Request_URI ^/media/download/ force-download

<IfDefine force-download>
    Header set Content-Disposition attachment
    Header set Content-Type application/octet-stream
</IfDefine>
+1

IfDefine , Apache, . :

SetEnvIf Request_URI ^/media/download/ force-download
Header set Content-Disposition attachment env=force-download

, .

+4

Source: https://habr.com/ru/post/1717744/


All Articles