0

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
5
  • Can't you put a separate htaccess file inside the admin directory? Sep 6, 2017 at 10:03
  • @axel.michel That would only work for files that reside inside the admin directory. The assets mentioned in the .htaccess file probably are located somewhere else and are - again probably - the same for both sections (admin / non-admin).
    – jeroen
    Sep 6, 2017 at 10:05
  • my file/directory structure if different and i am using symfony framework(php) Sep 6, 2017 at 10:05
  • Do you have access to your server config? You could use 'location' for this - but location is not allowed in htaccess, you'll need to modify httpd.conf, see httpd.apache.org/docs/2.2/mod/core.html#location Sep 6, 2017 at 10:15
  • Can you tell us your symfony version / setup? Do you use Assetic? Sep 6, 2017 at 10:19

2 Answers 2

1

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.

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.