在Apache htaccess

时间:2016-08-11 13:26:07

标签: apache .htaccess

我有一个带有标准.htaccess文件的PHP Laravel应用程序,如下所示。

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

如果请求的URL映射到静态文件,则会提供该URL,否则将调用index.php。我需要为静态文件添加一组标题,这可能是上面最后两个条件的“其他”。我需要类似下面伪的东西。

if static file
    Header set MyHeaderOne "something"
    Header set MyHeaderTwo "something"
end if

我可以添加标题就好了,但有条件地坚持这样做。我看了一下SetEnvIf,这可能使它成为可能。

那么,如何为静态文件添加一些标题,即如果所请求的文件存在(例如/images/example.jpg)?非常感谢提前!

1 个答案:

答案 0 :(得分:4)

你可以像你所说的那样做一个条件陈述。

objectID

https://httpd.apache.org/docs/2.4/expr.html#examples

相关问题