title: htaccess disable cache for specific URLs
body: <p>I use .htaccess to cache my images, JS and CSS files onmy website's front end.
  The website is built under Codeigniter 2.</p>
  
  <p>Here is my code :</p>
  
  <pre><code>RewriteEngine on
  
  #RewriteRule ^index\.php / [R=301]
  
  RewriteCond %{THE_REQUEST} index\.php
  RewriteRule ^index.php(?:/(.*))?$ https://www.mywebsite.com/$1 [R=301,L]
  
  
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond $1 !^(index\.php|resources|robots\.txt)
  RewriteRule ^(.*)$ index.php/$1 [L,QSA]
  
  #Compression Gzip
  &lt;IfModule mod_deflate.c&gt;
  AddOutputFilterByType DEFLATE application/x-javascript application/javascript 
  text/javascript text/css text/html text/xml
  &lt;/IfModule&gt;
  
  # Cache One month for most static assets
  &lt;filesMatch ".(jpg|jpeg|png|gif|ico)$"&gt;
  Header set Cache-Control "max-age=2628000, public"
  &lt;/filesMatch&gt;
  
  #Force la redirection vers www.
  #RewriteCond %{HTTP_HOST} !^www\.mywebsite\.com$ [NC]
  #RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
  #RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
  #RewriteRule .? https://www.mywebsite.com%{REQUEST_URI} [R=301,L]
  
  RewriteCond %{SERVER_PORT} 80 
  RewriteRule ^(.*)$ https://www.mywebsite.com/$1 [R,L]
  
  
  
  
  &lt;IfModule mod_deflate.c&gt;
     AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
    AddOutputFilterByType DEFLATE application/x-font
    AddOutputFilterByType DEFLATE application/x-font-opentype
    AddOutputFilterByType DEFLATE application/x-font-otf
    AddOutputFilterByType DEFLATE application/x-font-truetype
    AddOutputFilterByType DEFLATE application/x-font-ttf
     AddOutputFilterByType DEFLATE application/x-javascript
     AddOutputFilterByType DEFLATE application/xhtml+xml
     AddOutputFilterByType DEFLATE application/xml
     AddOutputFilterByType DEFLATE font/opentype
     AddOutputFilterByType DEFLATE font/otf
     AddOutputFilterByType DEFLATE font/ttf
     AddOutputFilterByType DEFLATE image/svg+xml
    AddOutputFilterByType DEFLATE image/x-icon
     AddOutputFilterByType DEFLATE text/css
     AddOutputFilterByType DEFLATE text/html
     AddOutputFilterByType DEFLATE text/javascript
     AddOutputFilterByType DEFLATE text/plain
   &lt;/IfModule&gt;
  
  
   &lt;IfModule mod_gzip.c&gt;
     mod_gzip_on Yes
     mod_gzip_dechunk Yes
     mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
     mod_gzip_item_include handler ^cgi-script$
     mod_gzip_item_include mime ^text/.*
     mod_gzip_item_include mime ^application/x-javascript.*
     mod_gzip_item_exclude mime ^image/.*
     mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
   &lt;/IfModule&gt;
  
  
  
   &lt;IfModule mod_expires.c&gt;
     ExpiresActive On
     ExpiresByType image/jpg "access 1 year"
     ExpiresByType image/jpeg "access 1 year"
     ExpiresByType image/gif "access 1 year"
     ExpiresByType image/png "access 1 year"
     ExpiresByType text/css "access 1 month"
     ExpiresByType text/html "access 1 month"
     ExpiresByType application/pdf "access 1 month"
     ExpiresByType text/x-javascript "access 1 month"
     ExpiresByType application/x-shockwave-flash "access 1 month"
     ExpiresByType image/x-icon "access 1 year"
     ExpiresDefault "access 1 month"
   &lt;/IfModule&gt;
   &lt;IfModule mod_headers.c&gt;
     &lt;filesmatch "\.(ico|flv|jpg|jpeg|png|gif|css|swf)$"&gt;
     Header set Cache-Control "max-age=2678400, public"
     &lt;/filesmatch&gt;
     &lt;filesmatch "\.(html|htm)$"&gt;
     Header set Cache-Control "max-age=7200, private, must-revalidate"
     &lt;/filesmatch&gt;
     &lt;filesmatch "\.(pdf)$"&gt;
     Header set Cache-Control "max-age=86400, public"
     &lt;/filesmatch&gt;
     &lt;filesmatch "\.(js)$"&gt;
     Header set Cache-Control "max-age=2678400, private"
     &lt;/filesmatch&gt;
   &lt;/IfModule&gt;
  </code></pre>
  
  <p>It works fine. However, when I am working in the backend (www.mywebsite/admin), the cache also applies, which is pretty anoying when updating images and texts.</p>
  
  <p>I have tried this solution at the very bottom of my htaccess file :<br>
  <a href="https://stackoverflow.com/questions/20581909/htaccess-disable-cache-if-url-contains-string">htaccess Disable cache if URL contains string?</a><br>
  but my content is still read from the memory cache.</p>
  
  <p>I also tried the "Location" and "LocationMatch" directive, but it creates an Internal Server Error : </p>
  
  <pre><code>&lt;Location  /admin&gt;
  FileETag None
  Header unset ETag
  Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
  Header set Pragma "no-cache"
  Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
  &lt;/Location &gt;
  </code></pre>
  
  <p>Is there someone who could help on this please ? 
  Thanks !</p>