I have set my htaccess file to cache and deflate the majority of the usual file types to increase speed, one file particularly though seems to behave oddly when cached and I want to try to exlude this from any deflate and caching commands in htaccess to see if that is the cause.
Because my site is fairly busy it does not make sense to take off all files and slow every user down while I check this over a couple of days so I was wondering?
Is there a line I can put in my htaccess that specifically excludes a particular file (engine.js for example)
regards
You could try something like this:
<Files (whatever you have this set to deflate)>
SetOutputFilter DEFLATE
</Files>
<Files (filename).(extension)>
SetOutputFilter NONE
</Files>
For example, if you were trying to deflate the PHP files, except for one, your code would look like this:
<Files *.php>
SetOutputFilter DEFLATE
</Files>
<Files myfile.php>
SetOutputFilter NONE
</Files>
Related
Google page speed tool tells me this: "Compressing resources with gzip or deflate can reduce the number of bytes sent over the network"
and of course lists all my .js and .css files.
Researching here eventually led me to this question:
How to Specify "Vary: Accept-Encoding" header in .htaccess
Which seems to say that for just .js and .css files all I would need to do is this:
<IfModule mod_deflate.c>
#The following line is enough for .js and .css
AddOutputFilter DEFLATE js css
</IfModule>
<IfModule mod_headers.c>
<FilesMatch "\.(js|css)$">
Header append Vary: Accept-Encoding
</FilesMatch>
</IfModule>
Can someone confirm that this is the current "best practice" for this objective and that it is failsafe, assuming the user is on a modern browser (e.g. not < IE7 for example)
Thanks!
I'm trying to force the download of all files of one folder.
The link on the page looks like this
Click to download
And I have this snippet in my .htaccess
<filesMatch ".*uploads/documents.*">
ForceType application/octet-stream
Header set Content-Disposition attachment
</filesMatch>
I already know that the 2 lines inside the tag works, because it works when I put a .htaccess directly inside the folder where I want to force the download with the following code:
<Files *.*>
ForceType application/octet-stream
Header set Content-Disposition attachment
</Files>
There seems to be something which I don't understand about the filesMatch tag.
Searching more info found this code:
<FilesMatch "\.(mov|mp3|jpg|pdf|mp4|avi|wmv)$">
ForceType application/octet-stream
Header set Content-Disposition attachment
</FilesMatch>
Worked for me.
Please look at the documentation for FilesMatch and Files, respectively. It clearly states
The directives given within this section will be applied to any object
with a basename (last component of filename) matching the specified
filename.
That means that in your example it matches against file.pdf. Your second example *.* matches file.pdf, however your first example .*uploads/documents.* does not. It actually can never match, since it contains a slash, which is used as a directory separator.
If you can edit the apache config
You should enclose either <Files *.*> or <Files *.pdf> (depending on what you want to enforce downloading) in a Location directive:
<Location "/uploads/documents/">
<Files *.*>
ForceType application/octet-stream
Header set Content-Disposition attachment
</Files>
</Location>
If you cannot edit the apache config
Unfortunately, the Location directive is not allowed inside .htaccess files. Just create a .htaccess inside your /uploads/documents/ directory.
This code is perfect if you don't use - in the file name!
For example, for name-1.mp3, change to name1.mp3
<FilesMatch "\.(mp3|avi)$" >
ForceType application/octet-stream
Header add Content-Disposition "attachment"
</FilesMatch>
Clear your browser and check it.
How would I tell the browser to force download all file types in a directory instead of rendering them inside the browser?
I've tried this but it didn't work.
<Files *.*>
ForceType applicaton/octet-stream
</Files>
This would be better tasked with:
<Files *.*>
Header set Content-Disposition attachment
</Files>
I use this with a FilesMatch instead of Files. Below is an example with text-based files
<FilesMatch "\.(?i:doc|odf|pdf|rtf|txt)$">
Header set Content-Disposition attachment
</FilesMatch>
I'm not sure that is possible. But you can use a mod_rewrite to a .php file with the file name in the GET part of the URL. Then extract the file name and force a download through that. If you want some download code, just ask
We have a multisite CMS that handles images and other files like this..
How can we cache images and other files that are in www.(or non-www.)variable-domain.com/files/* with .htaccess?
This is causing a 500 error. I stripped out some.. here is what I have currently that works (minus the Directory and contents part - it throws the error when thats included).
#
# Force Browser Cache
#
<ifmodule mod_expires.c>
ExpiresActive On
<filesmatch "\.(jpg|gif|png|css|js)$">
ExpiresDefault "access plus 1 year"
</filesmatch>
<FilesMatch ".(flv|gif|jpg|jpeg|png|ico|swf)$">
Header set Cache-Control "max-age=2592000"
</FilesMatch>
<FilesMatch ".(js|css|pdf|txt)$">
Header set Cache-Control "max-age=604800"
</FilesMatch>
<Directory "/home/aiwebsystems/public_html/uploads">
<FilesMatch "\.(gif|jpg|png|js|css)$">
ExpiresDefault "access plus 1 year"
</FilesMatch>
</Directory>
</ifmodule>
I would need all subdirectories of this included too...
Thanks for the help!
Use Apache's mod_expires
e.g in your .htaccess put:
ExpiresActive On
<Directory "/path/to/public_html/files">
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
ExpiresDefault A300
<FilesMatch "\.html$">
Expires A86400
</FilesMatch>
<FilesMatch "\.(gif|jpg|png|js|css)$">
Expires A2592000
</FilesMatch>
</Directory>
A300 meaning that the user cached copy expires 300 seconds after access. (A86400 is a day after access, A2592000 is a month after access)
If you mean server side caching, well then you are in luck as the operating system caches recently using a 'paging' algorithm: http://en.wikipedia.org/wiki/Paging
<Directory> is not allowed in htaccess.
Just create a new .htaccess file, with the expires stuff, and put it inside the 'uploads' directory. This will have the same effect you try to achief
Being as it does not have an extension, none of this worked. I change the code in the end and it works great now, using the file name rather than the image ID as the last URI parameter.
I use this code to concatenare CSS and Javascript:
<FilesMatch "\.combined\.js$">
Options +Includes
AddOutputFilterByType INCLUDES application/javascript application/json
SetOutputFilter INCLUDES
</FilesMatch>
<FilesMatch "\.combined\.css$">
Options +Includes
AddOutputFilterByType INCLUDES text/css
SetOutputFilter INCLUDES
</FilesMatch>
but it doesnt work
So you're using
<!--#include file="path/to/a/file.js" -->
<!--#include file="path/to/another/file.js" -->
in a master JS or CSS file, right?
This is what is being enabled by the .htaccess code posted in your question.
I also used same code for concatenating my js and css file. It works pefectly in my local machine..but don't work in live. I am using ubutu linux server.