2014-01-22 20 views
2

我需要mod_headers根据GET参数强制下载文件。上述mod_headers模块不加载,尽管它在httpd.conf中启用

<FilesMatch "*.gif"> 
    <If "%{QUERY_STRING} =~ /dl/"> 
     #Download header 
     Header set Content-Disposition "attachment" 
    </If> 
    </FilesMatch> 

代码会产生错误500。不过,如果我在<IfModule>妥善包装它,它根本不会做任何事情:

<IfModule mod_headers> 
    <FilesMatch "*.gif"> 
    <If "%{QUERY_STRING} =~ /dl/"> 
     Header set Content-Disposition "attachment" 
    </If> 
    </FilesMatch> 
</IfModule> 

这让我觉得,mod_headers没有在加载所有。但我有它在httpd.conf启用:

...
的LoadModule filter_module模块/ mod_filter.so
的LoadModule headers_module模块/ mod_headers.so
#的LoadModule heartbeat_module模块/ mod_heartbeat.so
。 ..

是否有任何调试日志找出哪些mods已被加载,哪些不是?

回答

1

您需要检查为mod_headers.c模块:

<IfModule mod_headers.c> 

(见this answer有关的.so/.c的东西)

但原因你得到500错误是双重的。

首先,<FilesMatch>容器需要一个正则表达式,“* .gif”不是有效的正则表达式。您可能只想使用<Files>容器。

其次,<If>不适用于apache 2.2,只有版本2.4。如果你不使用apache 2.4,那么你将无法使用<If>容器。

相关问题