.htaccesssubdomainbrowser-cachemod-expiresexpires-header

Set an .htaccess file for every directory


I'm working on multiple subdomains on my domain. I just finished working on one and want to specify cache headers for this specific subdomain. I dont want the other subdomains to also enable the cache headers, just the single one i finished working on.

So, expire headers should work for subdomain A, but not for subdomain B and C.

I have no clue how to achieve this and can't find a similar question.

My current .htaccess file

<IfModule mod_expires.c>
    # Enable expirations
    ExpiresActive On 
    # Default directive
    ExpiresDefault "access plus 1 month"
    # My favicon
    ExpiresByType image/x-icon "access plus 1 year"
    # Images
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType image/jpg "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    # CSS
    ExpiresByType text/css "access plus 1 month"
    # Javascript
    ExpiresByType application/javascript "access plus 1 year"
</IfModule>

Solution

  • You can use the <If> directive in htaccess context to match against the HTTP_HOST variable:

    <If "%{HTTP_HOST} =~ /(www\.)?subdomainA\.example\.com$/">
        # List of expires directives here
    </If>