Melissa2019B

Member
Jan 29, 2019
9
1
3
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 ##
 
Last edited by a moderator:

cPanelLauren

Product Owner
Staff member
Nov 14, 2017
13,295
1,272
313
Houston
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!
 

Melissa2019B

Member
Jan 29, 2019
9
1
3
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?
 
Last edited by a moderator:

Melissa2019B

Member
Jan 29, 2019
9
1
3
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?