To create an exception in htaccess mod_expires

Asked

Viewed 25 times

1

I have a website that I use mod_expires to cache, but I didn’t want to apply to all pages, because the home page, for example, is dynamic, changes every day.

There is how I create an exception rule not to apply for certain pages?

This is the code I use in htaccess:

<IfModule mod_expires.c>
# Enable expirations
ExpiresActive On
# HTML
ExpiresByType text/html "access plus 2 days"
</IfModule>

1 answer

1

If you are Apache 2.4 you can use <If>, using for example:

<If "%{REQUEST_URI} =~ /^\/caminho-exemplo\/foo\/bar\//">
    # se começar com /caminho-exemplo/foo/bar/
    # algo aqui
</If>
<ElseIf "%{REQUEST_URI} =~ /^\/user\/[a-zA-Z\-]+\/?$/">
    # se casar/match com /user/<nome do usuário de A a Z e hifén>/
    # algo aqui
</ElseIf>
<ElseIf "Outra IF aqui">
    # algo aqui
</ElseIf>
<Else>
    # algo aqui em exceção a todos anteriores
</Else>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.