htaccess设置环境变量

时间:2016-02-12 18:12:24

标签: .htaccess environment-variables

我正在尝试使用以下代码,但似乎永远不会设置环境变量SETEXPIRE。如果我删除它有效的IfDefine SETEXPIRE部分,但我需要那部分。

Options +FollowSymLinks -MultiViews

# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} (^|&)_=(.*)
RewriteRule .* - [E=SETEXPIRE:yes]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^html/(.*?)$ index.php?url=$1&%{QUERY_STRING} [L,NC]

<IfDefine SETEXPIRE>
    <filesMatch "(?!\.(png|jpe?g|css|js|gif))$">
        <IfModule mod_expires.c>
            ExpiresActive On
            ExpiresDefault "access plus 3 months"

            <IfModule mod_headers.c>
                Header set Cache-Control "max-age=2592000, public, no-transform"
                Header set pragma ""
            </IfModule>
        </IfModule>
    </filesMatch>
</IfDefine>

任何帮助都将不胜感激。

我想尝试做的是设置expire头,如果请求的文件扩展名是png | jpe?g | css | js | gif和查询字符串中设置了key _

1 个答案:

答案 0 :(得分:0)

thnx to mike我找到了解决方案:

 Options +FollowSymLinks -MultiViews
 # Turn mod_rewrite on
 RewriteEngine On
 RewriteBase /

 RewriteCond %{QUERY_STRING} (^|&)_=(.*)
 RewriteCond %{QUERY_STRING} !(^|&)_=0(&|$)
 RewriteRule .* - [E=SETEXPIRE:yes]

 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteRule ^html/(.*?)$ index.php?url=$1&%{QUERY_STRING} [L,NC]

 <filesMatch "(?!\.(png|jpe?g|css|js|gif))$">
       Header set Cache-Control "max-age=2592000, public, no-transform" env=SETEXPIRE
       Header set pragma "" env=SETEXPIRE
  </filesMatch>

欢呼声 c_bb