Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Customizing htaccess question

Discussion in 'Workarounds and Optimization' started by Melissa2019B, May 9, 2019.

  1. Melissa2019B

    Melissa2019B Member

    Joined:
    Jan 29, 2019
    Messages:
    9
    Likes Received:
    1
    Trophy Points:
    3
    Location:
    Denver
    cPanel Access Level:
    Website Owner
    Could someone please check this and see if everything looks correct and like it would work?
    I'm a beginner and someone did this for me, but I need to be sure that it will work, and not cause harm to the site. Thanks!
    Code:
    RewriteEngine On
    
    # Remove www from any URLs that have them
    # make all urls with www goto https non www
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^www\.
    RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
    
    #Next fix it so all traffic is re-routed to https version of site
    # make all urls https with out www go to https
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    
    # Modifications for speed  March 9th 2019
    
    # 2 weeks for most static assets
    # set for two weeks max 14 days (60sec * 60min * 24hours * 14days)
    <filesMatch ".(css|jpg|jpeg|png|gif|js|ico|php|html)$">
    Header set Cache-Control "max-age=1209600, public"
    </filesMatch>
    
    # Turn off etags
    Header unset Etag
    FileETag none
    
    <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>
    
    ## EXPIRES CACHING ##
    <IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpg "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    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 ##
    
    
     
    #1 Melissa2019B, May 9, 2019
    Last edited by a moderator: May 9, 2019
  2. cPanelLauren

    cPanelLauren Forums Analyst II Staff Member

    Joined:
    Nov 14, 2017
    Messages:
    6,237
    Likes Received:
    478
    Trophy Points:
    233
    Location:
    Houston
    cPanel Access Level:
    DataCenter Provider
    It looks fine, but I can't tell you if it will cause issues with your site, most likely it won't. In the event there is an issue caused by the .htaccess just remove the .htaccess.


    Thanks!
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. Melissa2019B

    Melissa2019B Member

    Joined:
    Jan 29, 2019
    Messages:
    9
    Likes Received:
    1
    Trophy Points:
    3
    Location:
    Denver
    cPanel Access Level:
    Website Owner
    Thank you Lauren!
     
  4. Melissa2019B

    Melissa2019B Member

    Joined:
    Jan 29, 2019
    Messages:
    9
    Likes Received:
    1
    Trophy Points:
    3
    Location:
    Denver
    cPanel Access Level:
    Website Owner
    Oh, I was just checking GT Metrix, after adding the above to the htaccess file and uploading it, and Yslow said:

    Add Expires headers F (45)

    It showed this Google stuff - much of it js.?:

    - Removed -

    So I'm confused. I have and Expires Caching section with:

    ExpiresByType text/x-javascript "access plus 1 month"

    Is that not what they're talking about?

    I looked it up at another site and it says:

    # One month for most static assets
    <filesMatch ".(css|jpg|jpeg|png|gif|js|ico)$">
    Header set Cache-Control "max-age=2628000, public"
    </filesMatch>

    Are these saying the same thing, or which should I use?
     
    #4 Melissa2019B, May 9, 2019
    Last edited by a moderator: May 9, 2019
  5. Infopro

    Infopro cPanel Sr. Product Evangelist Staff Member

    Joined:
    May 20, 2003
    Messages:
    16,899
    Likes Received:
    482
    Trophy Points:
    583
    Location:
    Pennsylvania
    cPanel Access Level:
    Root Administrator
    Twitter:
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. Melissa2019B

    Melissa2019B Member

    Joined:
    Jan 29, 2019
    Messages:
    9
    Likes Received:
    1
    Trophy Points:
    3
    Location:
    Denver
    cPanel Access Level:
    Website Owner
    Yes Infopro, but that seems to be what I have now, yet they're saying at Yslow that I need it anyway. That was why I was thinking that perhaps the

    # One month for most static assets
    <filesMatch ".(css|jpg|jpeg|png|gif|js|ico)$">
    Header set Cache-Control "max-age=2628000, public"
    </filesMatch>

    is doing something different?
     
  7. Melissa2019B

    Melissa2019B Member

    Joined:
    Jan 29, 2019
    Messages:
    9
    Likes Received:
    1
    Trophy Points:
    3
    Location:
    Denver
    cPanel Access Level:
    Website Owner
    Oh wait! I DO have both, but Yslow is apparently complaining on js that resides on Google's site!
     
  8. Infopro

    Infopro cPanel Sr. Product Evangelist Staff Member

    Joined:
    May 20, 2003
    Messages:
    16,899
    Likes Received:
    482
    Trophy Points:
    583
    Location:
    Pennsylvania
    cPanel Access Level:
    Root Administrator
    Twitter:
    Details! Now you're cooking with gas! :)
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
    cPanelLauren and Melissa2019B like this.
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice