Note that there are some explanatory texts on larger screens.

plurals
  1. POManual content compression in Apache
    primarykey
    data
    text
    <p>I need a manual compression solution on Apache. My goals:</p> <ul> <li>Provide gzip-encoded content on my server along with uncompressed.</li> <li>Files are pre-compressed.</li> <li>Not all files are served compressed. I want to specify these files and the choice isn't type (extension) based.</li> <li>Many content-types (custom ones) are served, and new types are showing up from time to time. Also, file extension doesn't determine if it will be compressed or not (<strong>!!!</strong>).</li> <li>Keep overhead minimal (the less extra headers, the better).</li> <li>Always provide Content-Length header and never send chunked response (this disqualifies <code>mod_deflate</code>).</li> </ul> <hr> <h1>Ideal Functionality</h1> <p>Ideal functionality would work like that:</p> <ul> <li>Web client asks for file <code>file.ext</code>.</li> <li>If <code>file.ext.gz</code> exists on server: <ul> <li><code>Content-Encoding</code> is set to <code>gzip</code>.</li> <li><code>Content-Type</code> is set to value of <code>file.ext</code> (<strong>!!!</strong>).</li> <li>Server returns <code>file.ext.gz</code>.</li> </ul></li> <li>Otherwise, <code>file.ext</code> is returned.</li> </ul> <p>I tested a number of solutions, <a href="http://www.cravediy.com/59-Simple-gzip-Support-for-Apache-with-mod_rewrite.html" rel="nofollow">this article</a> contains a good compilation, but there was always a problem with parts marked with (<strong>!!!</strong>). I have hundreds of thousands of files and dozens of content types and because of that I'm looking for some automatic solution, without need of adding <code>ForceType</code> for each file.</p> <hr> <h1>What I tried</h1> <h2>Multiviews</h2> <p>How this works:</p> <ul> <li>Rename a file <code>file.ext</code> to <code>file.ext.en</code></li> <li>Create a file <code>file.ext.gz</code></li> <li><p>Configure Apache:</p> <pre> Options +MultiViews AddEncoding x-gzip .gz RemoveType .gz </pre></li> </ul> <p>Works almost as expected, except it requires the original file (<code>file.ext</code>) to not exist and it adds many (useless to me) headers (<code>TCN</code>, <code>Content-Language</code> and few more) that can't be removed (<code>Header unset</code> doesn't remove them).</p> <h2>Rewrite</h2> <p>How this works: - Create <code>file.ext.gz</code> file. - Configure Apache:</p> <pre><code>&lt;pre&gt; RewriteEngine On RewriteCond %{HTTP:Accept-Encoding} gzip RewriteCond %{REQUEST_FILENAME}.gz -f RewriteRule (.*)$ $1.gz [L] AddEncoding x-gzip .gz &lt;Files file.ext&gt; ForceType my-custom/mime-type &lt;/FilesMatch&gt; &lt;/pre&gt; </code></pre> <p>This works well, but requires a <code>ForceType</code> for each compressed file. As I said before, I can't rely on extensions because not all files of certain type will be compressed.</p> <h2><code>mod_deflate</code></h2> <p>I didn't investigate it too much, the problem is that if file is too big, then it's split into pieces and sent in chunks and <code>Content-Length</code> is not provided. Increasing size of compression buffers can't eliminate this problem.</p> <hr> <p><strong>Is it possible at all to configure Apache to work as I'd liked to?</strong></p> <p>I tried to dynamically get <code>Content-Type</code> of <code>file.ext</code> and set it to <code>file.ext.gz</code>, but I didn't find the way how to do this.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload