fhoech/gz.php/master/.htaccess - Htaccess File

fhoech/gz.php/master/.htaccess

# Minimal .htaccess file containing just the rules for gz.php and serving
# static .gz/.min files

# Turn on rewrite engine
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
</IfModule>

# BEGIN GZIP
# Force content type for known extensions
<FilesMatch ".css.(gz|min)$">
    ForceType text/css
</FilesMatch>
<FilesMatch ".html?.gz$">
    ForceType text/html
</FilesMatch>
<FilesMatch ".ico.gz$">
    ForceType image/x-icon
</FilesMatch>
<FilesMatch ".js.(gz|min)$">
    ForceType application/javascript
</FilesMatch>
<FilesMatch ".json.gz$">
    ForceType application/json
</FilesMatch>
<FilesMatch ".svg.gz$">
    ForceType image/svg+xml
</FilesMatch>
<FilesMatch ".txt.gz$">
    ForceType text/plain
</FilesMatch>
<FilesMatch ".xml.gz$">
    ForceType application/xml
</FilesMatch>
<FilesMatch ".xsl.gz$">
    ForceType application/xslt+xml
</FilesMatch>

# Set 'Vary' response header for .gz files and files that can be compressed
<FilesMatch ".(gz|min|css|html?|ico|js|json|svg|txt|xml|xsl)$">
    <IfModule mod_headers.c>
        Header always append Vary "Accept-Encoding"
    </IfModule>
</FilesMatch>

# Set encoding for .gz files
<IfModule mod_mime.c>
    # http://httpd.apache.org/docs/2.2/mod/mod_mime.html#addencoding:
    # "To make this long story short, you should always use x-gzip and x-compress
    # for these two specific encodings"
    AddEncoding x-gzip .gz
</IfModule>

<IfModule mod_rewrite.c>
    # STATIC CACHING, gzip-encoded file next to original
    # ONLY uncomment this if you plan to MANUALLY delete cached *.gz files
    # after originals are changed!
    #RewriteCond %{REQUEST_URI} .(css|html?|ico|js|json|svg|txt|xml|xsl)$
    ## If the user agent accepts gzip encoding...
    #RewriteCond %{HTTP:Accept-Encoding} gzip
    ## ...and if gzip-encoded version of the requested file exists (<file>.gz)...
    #RewriteCond %{REQUEST_FILENAME}.gz -f
    ## ...then serve the gzip-encoded file. Done.
    #RewriteRule ^ %{REQUEST_URI}.gz [L]

    # STATIC CACHING, gzip-encoded file in gz-cache folder
    # ONLY uncomment this if you plan to MANUALLY delete cached *.gz files
    # after originals are changed!
    #RewriteCond %{REQUEST_URI} .(css|html?|ico|js|json|svg|txt|xml|xsl)$
    ## If the user agent accepts gzip encoding...
    #RewriteCond %{HTTP:Accept-Encoding} gzip
    ## ...and if gzip-encoded version of the requested file exists (<file>.gz)...
    #RewriteCond %{DOCUMENT_ROOT}/gz-cache%{REQUEST_URI}.gz -f
    ## ...then serve the gzip-encoded file. Done.
    #RewriteRule ^ /gz-cache%{REQUEST_URI}.gz [L]

    # DYNAMIC CACHING. NEVER COMMENT THIS OUT!
    RewriteCond %{REQUEST_URI} .(css|html?|ico|js|json|svg|txt|xml|xsl)$
    # If the user agent accepts gzip encoding...
    RewriteCond %{HTTP:Accept-Encoding} gzip
    # ...and the requested file exists...
    RewriteCond %{REQUEST_FILENAME} -f
    # ...then use a PHP script to serve a compressed version. Done.
    RewriteRule ^ /gz.php [L,E=REQUEST_URI:%{REQUEST_URI}]

    # STATIC CACHING (MINIFICATION ONLY), minified file next to original
    # ONLY uncomment this if you plan to MANUALLY delete cached *.min files
    # after originals are changed!
    #RewriteCond %{REQUEST_URI} .(css|js)$
    ## If a minified version of the requested file exists (<file>.min)...
    #RewriteCond %{REQUEST_FILENAME}.min -f
    ## ...then serve the minified file. Done.
    #RewriteRule ^ %{REQUEST_URI}.min [L]

    # STATIC CACHING (MINIFICATION ONLY), minified file in gz-cache folder
    # ONLY uncomment this if you plan to MANUALLY delete cached *.min files
    # after originals are changed!
    #RewriteCond %{REQUEST_URI} .(css|js)$
    ## If a minified version of the requested file exists (<file>.min)...
    #RewriteCond %{DOCUMENT_ROOT}/gz-cache%{REQUEST_URI}.min -f
    ## ...then serve the minified file. Done.
    #RewriteRule ^ /gz-cache%{REQUEST_URI}.min [L]

    # DYNAMIC CACHING (MINIFICATION ONLY)
    RewriteCond %{REQUEST_URI} .(css|js)$
    # Or if the requested file exists...
    RewriteCond %{REQUEST_FILENAME} -f
    # ...then use a PHP script serve a minified version. Done.
    RewriteRule ^ /gz.php [L,E=REQUEST_URI:%{REQUEST_URI}]
</IfModule>
# END GZIP

On Github License

Files

Download PDF of Htaccess file
DOCUMENT_ROOT, REQUEST_FILENAME, REQUEST_URI, static

Comments

Apache