The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

mod-pagespeed and .htaccess

Discussion in 'Workarounds and Optimization' started by canou83, Nov 5, 2016.

Tags:
  1. canou83

    canou83 Well-Known Member

    Joined:
    Jul 20, 2016
    Messages:
    62
    Likes Received:
    7
    Trophy Points:
    8
    Location:
    France
    cPanel Access Level:
    Website Owner
    Hello. I just installed mod-pagespeed on my VPS server where there are several sites.

    My questions are:

    - Today my .htaccess looks like this :
    Code:
    # ----------------------------------------------------------------------
    # Apache configuration file
    # This file is best used in /apache2/httpd.conf, but works (slower) in .htaccess
    #
    # I've spent quite a bit of time compiling what I find to be optimial to me
    # and my server. This file is based on:
    # - HTML5BoilerPlate: GitHub - h5bp/html5-boilerplate: A professional front-end template for building fast, robust, and adaptable web apps or sites.
    # - W3 Edge: W3 EDGE - Innovation Redefined
    # - Yahoo! Best Practices: http://developer.yahoo.com/performance/rules.html
    # - Caching Tutorial: http://www.mnot.net/cache_docs/
    # - Personal experience
    #
    # v1.2 / 2013.07.01 / Greg Rickaby
    # ----------------------------------------------------------------------
    
    # Specify a Default Charset
    AddDefaultCharset utf-8
    
    # ----------------------------------------------------------------------
    # Cache Control via HTTP Headers + Expires
    # Generation of Expires and Cache-Control HTTP headers according to user-specified criteria
    # mod_headers - Apache HTTP Server
    # ----------------------------------------------------------------------
    
    # Expires Defaults
    <IfModule mod_expires.c>
        ExpiresActive On
        # Set default expires to 2 days
        ExpiresDefault A172800
        ExpiresByType text/css A31536000
        ExpiresByType application/x-javascript A31536000
        ExpiresByType text/x-component A31536000
        ExpiresByType text/html A3600
        ExpiresByType text/richtext A3600
        ExpiresByType image/svg+xml A3600
        ExpiresByType text/plain A3600
        ExpiresByType text/xsd A3600
        ExpiresByType text/xsl A3600
        ExpiresByType text/xml A3600
        ExpiresByType video/asf A31536000
        ExpiresByType video/avi A31536000
        ExpiresByType image/bmp A31536000
        ExpiresByType application/java A31536000
        ExpiresByType video/divx A31536000
        ExpiresByType application/msword A31536000
        ExpiresByType application/vnd.ms-fontobject A31536000
        ExpiresByType application/x-msdownload A31536000
        ExpiresByType image/gif A31536000
        ExpiresByType application/x-gzip A31536000
        ExpiresByType image/x-icon A31536000
        ExpiresByType image/jpeg A31536000
        ExpiresByType application/vnd.ms-access A31536000
        ExpiresByType audio/midi A31536000
        ExpiresByType video/quicktime A31536000
        ExpiresByType audio/mpeg A31536000
        ExpiresByType video/mp4 A31536000
        ExpiresByType video/mpeg A31536000
        ExpiresByType application/vnd.ms-project A31536000
        ExpiresByType application/x-font-otf A31536000
        ExpiresByType application/vnd.oasis.opendocument.database A31536000
        ExpiresByType application/vnd.oasis.opendocument.chart A31536000
        ExpiresByType application/vnd.oasis.opendocument.formula A31536000
        ExpiresByType application/vnd.oasis.opendocument.graphics A31536000
        ExpiresByType application/vnd.oasis.opendocument.presentation A31536000
        ExpiresByType application/vnd.oasis.opendocument.spreadsheet A31536000
        ExpiresByType application/vnd.oasis.opendocument.text A31536000
        ExpiresByType audio/ogg A31536000
        ExpiresByType application/pdf A31536000
        ExpiresByType image/png A31536000
        ExpiresByType application/vnd.ms-powerpoint A31536000
        ExpiresByType audio/x-realaudio A31536000
        ExpiresByType image/svg+xml A31536000
        ExpiresByType application/x-shockwave-flash A31536000
        ExpiresByType application/x-tar A31536000
        ExpiresByType image/tiff A31536000
        ExpiresByType application/x-font-ttf A31536000
        ExpiresByType audio/wav A31536000
        ExpiresByType audio/wma A31536000
        ExpiresByType application/vnd.ms-write A31536000
        ExpiresByType application/vnd.ms-excel A31536000
        ExpiresByType application/zip A31536000
    </IfModule>
    
    # No caching for dynamic files
    <filesMatch "\.(php|cgi|pl|htm)$">
        ExpiresDefault A0
        Header set Cache-Control "no-store, no-cache, must-revalidate, max-age=0"
        Header set Pragma "no-cache"
    </filesMatch>
    
    # 1 MIN
    <filesMatch "\.(html)$">
        ExpiresDefault A60
        Header set Cache-Control "max-age=60, must-revalidate"
    </filesMatch>
    
    # 2 DAYS
    <filesMatch "\.(xml|txt)$">
        ExpiresDefault A172800
        Header set Cache-Control "max-age=172800, must-revalidate"
    </filesMatch>
    
    # 1 WEEK
    <filesMatch "\.(jpg|jpeg|png|gif|swf|js|css)$">
        ExpiresDefault A604800
        Header set Cache-Control "max-age=604800, must-revalidate"
    </filesMatch>
    
    # 1 MONTH
    <filesMatch "\.(ico|pdf|flv)$">
        ExpiresDefault A2419200
        Header set Cache-Control "max-age=2419200, must-revalidate"
    </filesMatch>
    
    # ----------------------------------------------------------------------
    # Mime Types
    # Mime Associates the requested filename's extensions with the file's behavior and content
    # mod_mime - Apache HTTP Server
    # ----------------------------------------------------------------------
    
    <IfModule mod_mime.c>
        AddType text/css .css
        AddType application/x-javascript .js
        AddType text/x-component .htc
        AddType text/html .html .htm
        AddType text/richtext .rtf .rtx
        AddType image/svg+xml .svg .svgz
        AddType text/plain .txt
        AddType text/xsd .xsd
        AddType text/xsl .xsl
        AddType text/xml .xml
        AddType video/asf .asf .asx .wax .wmv .wmx
        AddType video/avi .avi
        AddType image/bmp .bmp
        AddType application/java .class
        AddType video/divx .divx
        AddType application/msword .doc .docx
        AddType application/vnd.ms-fontobject .eot
        AddType application/x-msdownload .exe
        AddType image/gif .gif
        AddType application/x-gzip .gz .gzip
        AddType image/x-icon .ico
        AddType image/jpeg .jpg .jpeg .jpe
        AddType application/vnd.ms-access .mdb
        AddType audio/midi .mid .midi
        AddType video/quicktime .mov .qt
        AddType audio/mpeg .mp3 .m4a
        AddType video/mp4 .mp4 .m4v
        AddType video/mpeg .mpeg .mpg .mpe
        AddType application/vnd.ms-project .mpp
        AddType application/x-font-otf .otf
        AddType application/vnd.oasis.opendocument.database .odb
        AddType application/vnd.oasis.opendocument.chart .odc
        AddType application/vnd.oasis.opendocument.formula .odf
        AddType application/vnd.oasis.opendocument.graphics .odg
        AddType application/vnd.oasis.opendocument.presentation .odp
        AddType application/vnd.oasis.opendocument.spreadsheet .ods
        AddType application/vnd.oasis.opendocument.text .odt
        AddType audio/ogg .ogg
        AddType application/pdf .pdf
        AddType image/png .png
        AddType application/vnd.ms-powerpoint .pot .pps .ppt .pptx
        AddType audio/x-realaudio .ra .ram
        AddType application/x-shockwave-flash .swf
        AddType application/x-tar .tar
        AddType image/tiff .tif .tiff
        AddType application/x-font-ttf .ttf .ttc
        AddType audio/wav .wav
        AddType audio/wma .wma
        AddType application/vnd.ms-write .wri
        AddType application/vnd.ms-excel .xla .xls .xlsx .xlt .xlw
        AddType application/zip .zip
    </IfModule>
    
    # ----------------------------------------------------------------------
    # Gzip compression
    # Compress content before it is delivered to the client
    # mod_deflate - Apache HTTP Server
    # ----------------------------------------------------------------------
    
    <IfModule mod_deflate.c>
        SetOutputFilter DEFLATE
        <IfModule mod_setenvif.c>
            # Netscape 4.x has some problems...
            BrowserMatch ^Mozilla/4 gzip-only-text/html
          
            # Netscape 4.06-4.08 have some more problems
            BrowserMatch ^Mozilla/4\.0[678] no-gzip
          
            # MSIE masquerades as Netscape, but it is fine
            # BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
          
            # NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
            # the above regex won't work. You can use the following
            # workaround to get the desired effect:
            BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
          
            # Don't compress images
            SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary
        </IfModule>
      
        <IfModule mod_headers.c>
            # Make sure proxies don't deliver the wrong content
            Header append Vary User-Agent env=!dont-vary
        </IfModule>
    </IfModule>
    # ----------------------------------------------------------------------
    # Start rewrite engine
    # Provides a rule-based rewriting engine to rewrite requested URLs on the fly
    # mod_rewrite - Apache HTTP Server
    # ----------------------------------------------------------------------
    
    # FollowSymLinks must be enabled for this to work
    <IfModule mod_rewrite.c>
        Options +FollowSymlinks
        RewriteEngine On
    </IfModule>
    
    # Block access to "hidden" directories whose names begin with a period
    <IfModule mod_rewrite.c>
        RewriteBase /
        RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
        RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
        RewriteRule ^download/(.*) index.php?route=error/not_found [L]
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
        RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
        RewriteCond %{HTTP_HOST} ^aquamagasin.com$
        RewriteRule ^(.*) http://www.aquamagasin.com/$1 [QSA,L,R=301]
        RewriteCond %{QUERY_STRING} ^(.*)common/home(.*)$
        RewriteRule ^index\.php$ Aquamagasin [L,R=301]
    </IfModule>
    
    # ----------------------------------------------------------------------
    # Disable server signature (Security)
    # Configures the Server HTTP response header
    # core - Apache HTTP Server Version 2.2
    # ----------------------------------------------------------------------
    
    ServerSignature Off
    Header unset Etag
    FileETag none
    
    # ----------------------------------------------------------------------
    # Disable directory browsing (Security)
    # Generates directory indexes, automatically, similar to the Unix ls command or the Win32 dir shell command
    # mod_autoindex - Apache HTTP Server
    # ----------------------------------------------------------------------
    
    <IfModule mod_autoindex.c>
        Options -Indexes
    </IfModule>
    
    # ----------------------------------------------------------------------
    # Block access to backup and source files (Security)
    # This files may be left by some text/html editors and pose a great security danger
    # ----------------------------------------------------------------------
    
    <FilesMatch "(\.(bak|config|sql|fla|psd|ini|log|sh|inc|swp|dist)|~)$">
        Order allow,deny
        Deny from all
        Satisfy All
    </FilesMatch>
    
    # ----------------------------------------------------------------------
    # Increase cookie security (Security)
    # This files may be left by some text/html editors and pose a great security danger
    # ----------------------------------------------------------------------
    <IfModule php5_module>
        php_value session.cookie_httponly true
    </IfModule>
    
    # ----------------------------------------------------------------------
    # HTTP Response Headers
    #----------------------------------------------------------------------
    Header always append X-Frame-Options SAMEORIGIN
    Header set X-XSS-Protection 1;mode=block
    Header set X-Content-Type-Options nosniff
    
    # ----------------------------------------------------------------------
    # Webfont access
    # Allow access from all domains for webfonts.
    # ----------------------------------------------------------------------
    
    <IfModule mod_headers.c>
        <FilesMatch "\.(ttf|ttc|otf|eot|woff|font.css)$">
            Header set Access-Control-Allow-Origin "*"
        </FilesMatch>
    </IfModule>
    
    # ----------------------------------------------------------------------
    # Force latest IE rendering engine
    # ----------------------------------------------------------------------
    
    <IfModule mod_headers.c>
        Header set X-UA-Compatible "IE=Edge,chrome=1"
            # mod_headers can't match by content-type, but we don't want to this header on everything
            <FilesMatch "\.(js|css|gif|png|jpe?g|pdf|xml|oga|ogg|m4a|ogv|mp4|m4v|webm|svg|svgz|eot|ttf|otf|woff|ico|webp|appcache|manifest|htc|crx|oex|xpi|safariextz|vcf)$" >
                Header unset X-UA-Compatible
            </FilesMatch>
    </IfModule>
    
    # ----------------------------------------------------------------------
    # Instructs the proxies to cache two versions of the resource: one compressed, and one uncompressed.
    # https://developers.google.com/speed/docs/best-practices/caching#LeverageProxyCaching
    # ----------------------------------------------------------------------
    <IfModule mod_headers.c>
      <FilesMatch "\.(js|css|xml|gz)$">
        Header append Vary: Accept-Encoding
      </FilesMatch>
    </IfModule>
    
    # ----------------------------------------------------------------------
    # CORS-enabled images (@crossorigin)
    # Send CORS headers if browsers request them; enabled by default for images.
    # http://developer.mozilla.org/en/CORS_Enabled_Image
    # http://blog.chromium.org/2011/07/using-cross-domain-images-in-webgl-and.html
    # http://hacks.mozilla.org/2011/11/using-cors-to-load-webgl-textures-from-cross-domain-images/
    # http://wiki.mozilla.org/Security/Reviews/crossoriginAttribute
    # ----------------------------------------------------------------------
    
    <IfModule mod_setenvif.c>
        <IfModule mod_headers.c>
            <FilesMatch "\.(gif|png|jpe?g|svg|svgz|ico|webp)$">
                SetEnvIf Origin ":" IS_CORS
                Header set Access-Control-Allow-Origin "*" env=IS_CORS
            </FilesMatch>
        </IfModule>
    </IfModule>
    
    I guess there are things to retire now that I use mod_pagespeed? If yes, which ones ? Your advice is always welcome.

    - Is there a pagespeed.conf "Optimized" that is already sufficiently efficient file? A narrow recess next?

    Thanks a lot.
     
    #1 canou83, Nov 5, 2016
    Last edited by a moderator: Nov 5, 2016
  2. Infopro

    Infopro cPanel Sr. Product Evangelist
    Staff Member

    Joined:
    May 20, 2003
    Messages:
    15,618
    Likes Received:
    296
    Trophy Points:
    433
    Location:
    Pennsylvania
    cPanel Access Level:
    Root Administrator
    Twitter:
    I think the answer to this question is the same answer you got in this thread about that same htaccess:
    POST requests may be blocked
     
Loading...

Share This Page