1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Help me merge this 2 htaccess into 1

Discussion in 'Apache' started by kartik786, Nov 20, 2015.

  1. #1
    Hi, Can someone please help me merge these 2 htaccess into one?

    One developer had worked on minifying css, gzip etc but we faced some issue after some time so other developer created a different htaccess. While doing so, seems he missed some benefiting code of first developer.

    Now I want to merge both and create a good htaccess.

    Here's the first code:
    <IfModule mod_headers.c>
        Header set Connection keep-alive
    </IfModule>
    
    <IfModule mod_mime.c>
        AddType text/css .css
        AddType application/x-javascript .js
        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 image/gif .gif
        AddType application/x-gzip .gz .gzip
        AddType image/x-icon .ico
        AddType image/jpeg .jpg .jpeg .jpe
        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/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 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>
    <IfModule mod_expires.c>
    
    # Enable expirations
    ExpiresActive On
    
    # Default directive
    ExpiresDefault "access plus 1 year"
    
    # My favicon
    ExpiresByType image/x-icon "access plus 1 year”
    
    # Images
    ExpiresByType image/gif "access plus 1 year"
    ExpiresByType image/png "access plus 1 year"
    ExpiresByType image/jpg "access plus 1 year"
    ExpiresByType image/jpeg "access plus 1 year"
    
    # CSS
    ExpiresByType text/css "access 1 year
    
    # Javascript
    ExpiresByType application/javascript "access plus 1 month"
    ExpiresByType text/javascript           "access plus 1 month"
    ExpiresByType text/x-javascript "access 1 month"
    
    
    </IfModule>
    <IfModule mod_deflate.c>
        <IfModule mod_setenvif.c>
            BrowserMatch ^Mozilla/4 gzip-only-text/html
            BrowserMatch ^Mozilla/4\.0[678] no-gzip
            BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
            BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
        </IfModule>
        <IfModule mod_headers.c>
            Header append Vary User-Agent env=!dont-vary
        </IfModule>
        AddOutputFilterByType DEFLATE text/css application/x-javascript text/html text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon
    </IfModule>
    <FilesMatch "\.(css|js)$">
        <IfModule mod_headers.c>
            Header set Pragma "public"
            Header set Cache-Control "public, must-revalidate, proxy-revalidate"
        </IfModule>
        FileETag MTime Size
    </FilesMatch>
    <FilesMatch "\.(html|htm|rtf|rtx|svg|svgz|txt|xsd|xsl|xml)$">
        <IfModule mod_headers.c>
            Header set Pragma "public"
            Header set Cache-Control "public, must-revalidate, proxy-revalidate"
        </IfModule>
        FileETag MTime Size
    </FilesMatch>
    <FilesMatch "\.(asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|swf|tar|tif|tiff|wav|wma|wri|xla|xls|xlsx|xlt|xlw|zip)$">
        <IfModule mod_headers.c>
            Header set Pragma "public"
            Header set Cache-Control "public, must-revalidate, proxy-revalidate"
        </IfModule>
        FileETag MTime Size
    </FilesMatch>
    Code (markup):
    Here's the second :
    SEMrush
    RewriteEngine On
    Options +Followsymlinks
    
    <IfModule mod_expires.c>
    
    # Enable expirations
    ExpiresActive On
    
    # Default directive
    ExpiresDefault "access plus 1 hour"
    
    # My favicon
    ExpiresByType image/x-icon "access plus 1 month
    
    # Images
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType image/jpg "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    
    # CSS
    ExpiresByType text/css "access 1 month
    
    # Javascript
    ExpiresByType application/javascript "access plus 1 hour"
    ExpiresByType text/javascript           "access plus 1 hour"
    ExpiresByType text/x-javascript "access 1 hour"
    
    
    </IfModule>
    
    <IfModule mod_mime.c>
        AddType text/css .css
        AddType application/x-javascript .js
        AddType text/html .html .htm
        AddType text/xml .xml
        AddType image/gif .gif
        AddType application/x-gzip .gz .gzip
        AddType image/x-icon .ico
        AddType image/jpeg .jpg .jpeg .jpe
        AddType application/pdf .pdf
        AddType image/png .png
        AddType application/zip .zip
    </IfModule>
    <IfModule mod_deflate.c>
        <IfModule mod_setenvif.c>
            BrowserMatch ^Mozilla/4 gzip-only-text/html
            BrowserMatch ^Mozilla/4\.0[678] no-gzip
            BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
            BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
        </IfModule>
        <IfModule mod_headers.c>
            Header append Vary User-Agent env=!dont-vary
        </IfModule>
        AddOutputFilterByType DEFLATE text/css application/x-javascript text/html text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon
    </IfModule>
    
    Code (markup):
    Can we merge them?
     
    kartik786, Nov 20, 2015 IP
    SEMrush
  2. Jackel.ca

    Jackel.ca Well-Known Member

    Messages:
    106
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    128
    #2
    The first one looks like it has nearly the identical information in it. The only thing I can see is that the expiration times were adjusted. Can I safely assume you're getting cached results of your old CSS? If so, you may have to add a "version identifier" to your existing website source.

    Example:

    
    [link rel="stylesheet" href="http://yourwebsite.com/style.css?v=001" type="text/css" /]
    
    Code (markup):
    If that makes any sense..
     
    Jackel.ca, Nov 21, 2015 IP
    kartik786 likes this.
  3. Roger S

    Roger S Active Member

    Messages:
    46
    Likes Received:
    4
    Best Answers:
    1
    Trophy Points:
    58
    #3
    Hello,

    Both the files have nearly identical information.

    One part is the caching part where there are rules to enable caching and for how much time.

    The second part was to enable compression commonly known as gzip compression.

    The first one has some rules that classify the caching period for different files types. :)
     
    Roger S, Dec 26, 2015 IP
    kartik786 likes this.
  4. kartik786

    kartik786 Well-Known Member

    Messages:
    1,884
    Likes Received:
    59
    Best Answers:
    0
    Trophy Points:
    170
    #4
    Can we merge them so that we can enable gzip compression and caching in one .htaccess?
     
    kartik786, Dec 27, 2015 IP
  5. Roger S

    Roger S Active Member

    Messages:
    46
    Likes Received:
    4
    Best Answers:
    1
    Trophy Points:
    58
    #5
    Hello,

    Can you try the following.

    ## EXPIRES CACHING ##
    <IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpg "access plus 1 year"
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType image/gif "access plus 1 year"
    ExpiresByType image/png "access plus 1 year"
    ExpiresByType text/css "access plus 1 month"
    ExpiresByType application/pdf "access plus 1 month"
    ExpiresByType text/x-javascript "access plus 1 month"
    ExpiresByType application/x-shockwave-flash "access plus 1 month"
    ExpiresByType image/x-icon "access plus 1 year"
    ExpiresDefault "access plus 2 days"
    </IfModule>
    ## EXPIRES CACHING ##
    
    
    
    <IfModule mod_deflate.c>
      # Compress HTML, CSS, JavaScript, Text, XML and fonts
      AddOutputFilterByType DEFLATE application/javascript
      AddOutputFilterByType DEFLATE application/rss+xml
      AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
      AddOutputFilterByType DEFLATE application/x-font
      AddOutputFilterByType DEFLATE application/x-font-opentype
      AddOutputFilterByType DEFLATE application/x-font-otf
      AddOutputFilterByType DEFLATE application/x-font-truetype
      AddOutputFilterByType DEFLATE application/x-font-ttf
      AddOutputFilterByType DEFLATE application/x-javascript
      AddOutputFilterByType DEFLATE application/xhtml+xml
      AddOutputFilterByType DEFLATE application/xml
      AddOutputFilterByType DEFLATE font/opentype
      AddOutputFilterByType DEFLATE font/otf
      AddOutputFilterByType DEFLATE font/ttf
      AddOutputFilterByType DEFLATE image/svg+xml
      AddOutputFilterByType DEFLATE image/x-icon
      AddOutputFilterByType DEFLATE text/css
      AddOutputFilterByType DEFLATE text/html
      AddOutputFilterByType DEFLATE text/javascript
      AddOutputFilterByType DEFLATE text/plain
      AddOutputFilterByType DEFLATE text/xml
    
      # Remove browser bugs (only needed for really old browsers)
      BrowserMatch ^Mozilla/4 gzip-only-text/html
      BrowserMatch ^Mozilla/4\.0[678] no-gzip
      BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
      Header append Vary User-Agent
    </IfModule>
    
    Code (ApacheConf):


    Links for reference
    https://gtmetrix.com/leverage-browser-caching.html
    https://gtmetrix.com/enable-gzip-compression.html
     
    Roger S, Dec 27, 2015 IP
    kartik786 likes this.