how to delete header cache in htaccess? - .htaccess

In my htaccess file there is this :
<FilesMatch "\.(js|css|pdf|txt)$">
Header set Cache-Control "max-age=7257608"
</FilesMatch>
Now, if I wanted to alter a css type file. the css will change if I refreshed the page. Other users still get the old css file because of the cache. what can I do on my side to let the users browsers recognize there is a change in the css file?

Generally rather than setting a cache age in the .htaccess, make sure you're configured to use if-modified-since which is documented in the Apache Caching Guide, using the mod_cache extension:
Generally, it's as simple as this, with exceptions written for secured resources:
LoadModule mem_cache_module modules/mod_mem_cache.so
<IfModule mod_mem_cache.c>
CacheEnable mem /
MCacheSize 4096
MCacheMaxObjectCount 100
MCacheMinObjectSize 1
MCacheMaxObjectSize 2048
</IfModule>

Related

enable caching of images only in specific folder

I have the below htacess code and am wondering how i can specify it to only apply to a specific folder. in this case, only all image files in: /public_html/img/icons/
<filesMatch ".(png)$">
Header set Cache-Control "max-age=31536000, public"
</filesMatch>
Set an environment variable (using SetEnvIf) when the URL requested matches the specific folder and image type(s). Set the Header conditionally based on this env var (using the env= argument of the Header directive).
For example:
# Cache images in the "/img/icons" subdirectory
SetEnvIf Request_URI "^/img/icons/.+\.(png|jpg|gif)$" ENABLE_CACHE
Header set Cache-Control "max-age=31536000, public" env=ENABLE_CACHE
This method allows you to keep all the directives in the single .htaccess file in the document root. It also works on all versions of Apache (unlike <If> expressions that require Apache 2.4).
However, this may also be dependent on other directives you have in the .htaccess file. If, for instance, you are on Apache (as opposed to LiteSpeed) and rewriting the URL with mod_rewrite (a front-controller pattern perhaps) then you may need to test for REDIRECT_ENABLE_CACHE in the Header directive instead. (Or change your existing directives to prevent a loop of the rewrite engine, that results in the env var being prefixed with REDIRECT_.)

Access files outside of webroot through alias and .htaccess rule

I need to make PDF files that are stored in a folder (with subfolders) outside of the web root publically accessible by a plain URL. An alias has been created in Apache that leads this folder so what I need now is a redirect rule in .htaccess to make this work.
I have this alias: https://www.examplesite.com/certificate
The URLs that will be used to access these PDFs are for example: https://www.examplesite.com/certificate/2018/LGOIGD9E9345034GJERGJER.PDF
https://www.examplesite.com/certificate/2017/GSDFJGLKJNL345L34LSNFLSD.PDF
How should I format my redirect rule in .htaccess to decide if the file is to be downloaded or viewed in the browser?
Sorry about the noise, I found the answer by myself:
<FilesMatch "\.pdf$">
ForceType applicaton/octet-stream
Header set Content-Disposition attachment
</FilesMatch>

How to Force Download files via .htaccess

I am trying to make my site "www.suruleretv.co" files like mp3, mp4 to force download instead of streaming.
I've tried to add some codes in find online via .htaccess but am getting error after adding it.
<FilesMatch "\.mp3$">
ForceType application/octet-stream
Header set Content-Disposition attachment
</FilesMatch>
it would help if you could add your code to the question, to clarify what you want and to identify what the issue is.
However, if you want to force files to be downloaded, adding the following in your .htaccess should be enough:
<FilesMatch "\.(mp3|mp4)$">
ForceType application/octet-stream
Header set Content-Disposition attachment
</FilesMatch>
Please keep in mind, that if you only add this part and have nothing else in it, you will have to save your .htaccess file in the same directory as the downloadeable files. It won't work for subfolders, without adding more rules.

firefox and fontface htaccess

To make font-face work on FF I need to make a .htaccess file, upload it to the root directory and that should be it right?
so in a blank text file i write:
<FilesMatch "\.(ttf|otf|eot)$">
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
</FilesMatch>
I save it, I upload it to the site root and rename it to .htaccess
but it is not working, no matter what I do..
The strangest thing is that ff loads the fonts on some of the pages but not on all
Is there something else that should be added to the text/htaccess file?
Using htaccess as mentioned above did not solve anything, it actually just made things worse.
The solution was to make all paths relative.
I mean, EVERY path related to the fonts.

.htaccess cache static content (unless modified)?

Was wondering is this possible in .htaccess?
I'm currently caching .js, .css and all image files via PHP (and providing the cached only if the file has not been modified by checking the filemtime()).
However someone suggested it's possible via .htaccess and much faster, so was hoping maybe someone can shed some light...I've looked around and found various snippets but none which cover what I'm after.
If you've got mod_expires installed on your apache server you can put something like this in your .htaccess file. This example is PHP orientated (actually grabbed from the Drupal 7 .htaccess file) but should serve as a good starting point.
FileETag MTime Size
<IfModule mod_expires.c>
# Enable expirations.
ExpiresActive On
# Cache all files for 2 weeks after access (A).
ExpiresDefault A1209600
<FilesMatch \.php$>
# Do not allow PHP scripts to be cached unless they explicitly send cache
# headers themselves. Otherwise all scripts would have to overwrite the
# headers set by mod_expires if they want another caching behavior.
ExpiresActive Off
</FilesMatch>
</IfModule>

Resources