2009-09-15 2 views
3

나는 인라인 서비스를 제공하거나 사용자에게 요청 URI를 기반으로 다운로드 할 수있는 옵션을 제공하려는 mp3 파일의 디렉토리가 있습니다.URI를 기반으로 콘텐츠 처리를 변경하는 mod_rewrite 도움말

/media/file1.mp3 -이 경우 파일을 제공하고 브라우저에서 재생하도록하고 싶습니다.

/media/download/file1.mp3 -이 경우 사용자가 파일을 쉽게 다운로드 할 수있게하려고합니다.

mod_rewrite 및 php (header() 및 readfile() 함수 사용)로이 작업을 수행 할 수 있었지만 가능한 경우 mod_rewrite, mod_header 등을 사용하여 수행했습니다.

답변

1

mod_rewrite를 사용하면 특정 헤더 필드 만 변경할 수 있지만 Content-Disposition 헤더 필드는 속하지 않습니다. 당신은 단지 콘텐츠 형식 헤더 필드 변경할 수 있습니다 :

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> 
+0

감사합니다. 나는 이것을 성공적으로 시도하지 못했습니다. SetEnvIF Request_URI "^/media/download"force-download = 1 헤더 세트 Content-Disposition attachment env = force-download – syncopated

4

IfDefine을 시작 설정 변수를 확인합니다 아파치가 작동하지 않을 것이다. 유효한 설정은 다음과 같습니다 또한 콘텐츠 형식을 변경

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

다운로드를 강제 할 필요가 없습니다.

관련 문제