how to remove cache from admin panel using .htaccess

599 Views Asked by At

i have a single .htaccess file for both admin panel and website. In my website I am using apc cache for cache and it works fine in website, but in backend/admin panel there are lots of issues due to cache.

now i don't need a cache in admin panal but website i need a cache

So, please tell me how I can write a regex in .htaccess for both website as well as admin panel.

Currently I am using this 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 image/svg+xml "access 1 month"
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 plus 2 days"
</IfModule>
## EXPIRES CACHING ##

For example :

cache works on : www.xyz.com/
cache not works on : www.xyz.com/admin
2

There are 2 best solutions below

0
On

It looks like you are talking about assets like images, stylesheets and javascript.

Assuming that the assets are the same for the normal sections and the admin section, there is no easy way to do that in your .htaccess file: The browser will request the same urls, regardless whether the user is visiting a normal page or an admin page.

What you could do in your admin section in the code itself, is invalidating the cache by using unique filenames like /assets/css/style.css?v=UNIQUE_VERSION_NUMBER.

Here the unique version number could be the hash of your latest commit, a time-stamp, etc.

0
On

You can turn off by caching to a specific folder by using following code.

<Directory "your folder path(e.g. /www/htdocs/admin)">
    ExpiresActive Off
</Directory>

Hope this may resolve your issue.