添加页眉在阿帕奇 [英] Add header in apache
问题描述
我有这样的服务器上的Apache和许多图像。 E.摹: http://test.com/images/abc.jpg
我想有可能做这样的:如果用户访问网页这样 http://test.com/images/download/abc.jpg
阿帕奇必须添加标题内容处置:附件;文件名=abc.jpg的
。我该怎么办呢?
I have apache and many images on this server. E. g.: http://test.com/images/abc.jpg
I want to have possibility do this: if user go to url like this http://test.com/images/download/abc.jpg
apache must add header Content-Disposition: attachment; filename="abc.jpg"
. How I can do it?
推荐答案
您想使用mod_rewrite的组合(假冒的下载目录)和mod_headers中(添加的内容处理标头)。
You want to use a combination of mod_rewrite (to fake the "download" directory) and mod_headers (to add the Content-Disposition header).
创建的图像目录.htaccess文件:
Create a .htaccess file in the images directory:
<filesmatch ".*">
Header set Content-Disposition attachment env=REDIRECT_force_download
</filesmatch>
每当REDIRECT_force_download环境变量设置这将设置适当的头。
This will set the appropriate header whenever the "REDIRECT_force_download" environment variable is set.
创建一个下载目录,并添加此.htaccess文件:
Create a download directory and add this .htaccess file:
RewriteEngine On
RewriteRule (.*) ../$1 [L,NC,QSA,E=force_download:1]
这将重定向任何图像请求到父(图像)的目录,同时增加了REDIRECT_force_download环境变量会从上面触发头指令。
This will redirect any image requests to the parent (images) directory while adding the "REDIRECT_force_download" environment variable that will trigger the Header command from above.
这篇关于添加页眉在阿帕奇的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!