Vikas Sharma
Vikas Sharma

Reputation: 599

How to set expiry headers using htaccess for Yii cached files

I've a site in Yii framework and Yii version is 1.1.16

I've applied below code in my htaccess

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access 1 month"
</IfModule>
## EXPIRES CACHING ##

But when i check my site using Google page insights that it says that

https://www.example.com/assets/593f25af/images/dropdown.png (expiration not specified)

Also to manage cache I've added this code in my main.php file under config folder:

'cache' => array(
       'class' => 'CApcCache',
 ),

Can you guys please tell me, what i am doing wrong so expiry headers is not working for these cache files.

Please help me!

Upvotes: 0

Views: 864

Answers (2)

Vikas Sharma
Vikas Sharma

Reputation: 599

Thanks all for answering but later i realize that it is a server level problem. There was some issue with my Plesk hosting, i contacted hosting guys and they fixed it, Now same .htaccess code is working.

Upvotes: 0

Muhammad Omer Aslam
Muhammad Omer Aslam

Reputation: 23768

Can you try replacing your configurations with the following into your .htaccess

#
# configure mod_expires
#
# URL: http://httpd.apache.org/docs/2.2/mod/mod_expires.html
#
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresDefault "access plus 1 seconds"
    ExpiresByType image/x-icon "access plus 2692000 seconds"
    ExpiresByType image/jpeg "access plus 2692000 seconds"
    ExpiresByType image/vnd.microsoft.icon "access plus 2692000 seconds"
    ExpiresByType image/png "access plus 2692000 seconds"
    ExpiresByType image/gif "access plus 2692000 seconds"
    ExpiresByType application/x-shockwave-flash "access plus 2692000 seconds"
    ExpiresByType text/css "access plus 2692000 seconds"
    ExpiresByType text/javascript "access plus 2692000 seconds"
    ExpiresByType application/x-javascript "access plus 2692000 seconds"
    ExpiresByType text/html "access plus 600 seconds"
    ExpiresByType application/xhtml+xml "access plus 600 seconds"
</IfModule>


#
# configure mod_headers
#
# URL: http://httpd.apache.org/docs/2.2/mod/mod_headers.html
#
<IfModule mod_headers.c>
    <FilesMatch "\\.(ico|jpe?g|png|gif|swf|css|js)$">
        Header set Cache-Control "max-age=2692000, public"
    </FilesMatch>
    <FilesMatch "\\.(x?html?|php)$">
        Header set Cache-Control "max-age=600, private, must-revalidate"
    </FilesMatch>
    Header unset ETag
    Header unset Last-Modified
</IfModule>

Upvotes: 1

Related Questions