The following question is highly related to this one.
Apache version is 2.2, so no "If" statement is provided. The server contains only gzipped files, in order to save space. A user can request the gzipped file or just its decompressed content, depending on Accept-Encoding.
This is the pseudo-configuration for httpd.conf:
<Directory /data/compressed>
RewriteEngine on
# Check file exists
RewriteCond %{REQUEST_FILENAME}gz -s
# Append a .gz to the requested filename
RewriteRule ^(.+)\.txt$ $1\.txt\.gz [QSA]
# If request contains "Accept-Encoding: gzip":
# Set the appropriate Content-Type and Content-Encoding
Header set Content-Type "application/gzip"
Header set Content-Encoding "gzip"
# Else:
# Decompress the .gz
FilterDeclare gzip CONTENT_SET
FilterProvider gzip INFLATE req=Accept-Encoding !$gzip
FilterChain gzip
# Set the appropriate Content-Type and Content-Encoding
Header set Content-Type "text/plain"
Header unset Content-Encoding
# Serve the decompressed (.txt) file, without ending ".gz"
# ???
</Directory>
So if a client can handle compressed content, the server will simply retrieve the .gz file (NOTE: client specifically requests "file.txt" not "file.txt.gz") and serve it. If the client cannot handle compressed content the server will find the the .gz file, decompress it, change the headers accordingly and then serve the file.
I'm asking your help as cannot find a way to evaluate the if block using the Apache rules. Furthermore I'd like to know how to strip out the .gz from the uncompressed file before serving it.
Thank you.