Forum Moderators: phranque
AddEncoding x-gzip .js
AddEncoding x-gzip .htm
All files of this types are stored compressed on the server.
This saves also much time at uploading.
This works in 99,9% of all cases,
all modern browser, even old MSIE 5 understands
all important search engine spiders understand it
But seems there are some broken proxy servers deleting
the compress information in the header.
Any browser behind such a broken proxy does not
know, that it's compressed.
Is something like this possible?
for *.js and *.htm files
if ( accept enoding gzip ) { deliver file as is }
else { decompress and deliver }
You could:
Rename all compressed .html and .js files to .html.gz and .js.gz, and use mod_rewrite to internally rewrite requests for .html and .js URLs to .html.gz and .js.gz filepaths if the Accept-Encoding request header does not contain "gzip," and then change your AddEncoding so that only these .gz filetypes get the Encoding header applied.
-or-
Move all gzipped content into a saparate subdirectory-path (mirroring the existing structure), and again use mod_rewrite to internally rewrite requests for xyz.html and xyz.js URLs to /<subdirectory-path>/xyz.html and /<subdirectory-path>/xyz.js filepaths if the Accept-Encoding header does not contain "gzip," and then change your AddEncoding so that only these /<subdirectory-path> files get the Encoding header applied.
In the first case, you'd surround your AddEncoding directives with a <Files> or <FilesMatch> container specifying the .gz extension, and in the second case, you'd surround those diretives with a <Directory> or <DirectoryMatch> container.
Similarly, you would then use mod_rewrite to internally rewrite requests for .html and .js URLs based the non-gzip Accept-Encoding header to a script that will decompress the .html.gz and .js.gz files to plain HTML (.html) or text (.js) for delivery without the Encoding header.
Note that in the first case, I'm suggesting that gzipped files be stored with filesnames ending .gz which requires renaming all the files. While this may seem like a hassle, it would greatly benefit the maintainability of the site, since the files will be clearly tagged with their correct filetype, thus avoiding headaches in the future due to the filetype not matching the actual content on the server; It is simply "cleaner" and "more correct."
There may be other/better ways to do this; The above are just two relatively straightforward suggestions.
Jim
index.jpg -> index.jpg
index.htm.gz -> index.htm
e.js.gz -> e.js
Works all fine, is designed that all know compressed deliery.
Now I think to ad in .htaccess something to redirect all traffic unable for compressed delivery to
cgi.example.com/unable.htm
"You are here because Your system can not used compressed delivery...."
cgi.example.com would in this case be the only subdomain without compressed delivery.
Please could You tell me, how I can make this in .htaccess?
Redirect on unable for compressed delivery?