How do I edit the htaccess file to optimize my website?

Hi I have tried to optimize my website energyshop.se for a cpl of days but I cant seem to get it done. This is how my .htaccess looks like:

Header unset ETag
FileETag None
# Hantera och redirecta användare till en gemensam error-sia
ErrorDocument 404 /psych/cgi-bin/error/error?404 

# BEGIN Compress text files 
<ifModule mod_deflate.c>
  <filesMatch "\.(css|js|x?html?|php)$">
    SetOutputFilter DEFLATE
  </filesMatch>
</ifModule>
# END Compress text files 

# BEGIN Expire headers 
<IfModule mod_expires.c>
ExpiresActive On
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf|form)$">
ExpiresDefault "access plus 1 year"
</FilesMatch>
</IfModule>
# END Expire headers 

# BEGIN Cache-Control Headers 
<ifModule mod_headers.c>
  <filesMatch "\.(ico|jpe?g|png|gif|swf)$">
    Header set Cache-Control "max-age=2592000, public"
  </filesMatch>
  <filesMatch "\.(css)$">
    Header set Cache-Control "max-age=604800, public"
  </filesMatch>
  <filesMatch "\.(js)$">
    Header set Cache-Control "max-age=216000, private"
  </filesMatch>
  <filesMatch "\.(x?html?|php)$">
    Header set Cache-Control "max-age=600, private, must-revalidate"
  </filesMatch>
</ifModule>
# END Cache-Control Headers 

# BEGIN Turn ETags Off 
<ifModule mod_headers.c>
  Header unset ETag
</ifModule>
FileETag None
# END Turn ETags Off 

# BEGIN Remove Last-Modified Header 
<ifModule mod_headers.c>
  Header unset Last-Modified
</ifModule>
# END Remove Last-Modified Header

# BEGIN Gzip Compression
<ifModule mod_gzip.c>
  mod_gzip_on Yes
  mod_gzip_dechunk Yes
  mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
  mod_gzip_item_include handler ^cgi-script$
  mod_gzip_item_include mime ^text/.*
  mod_gzip_item_include mime ^application/x-javascript.*
  mod_gzip_item_exclude mime ^image/.*
  mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
# END Gzip Compression

AddDefaultCharset UTF-8
DefaultLanguage sv-SE

# Force “File Save As” Prompt
AddType application/octet-stream .avi .mpg .mov .pdf .xls .mp4 .rar

But the problem is that when I run tests they still say that I containing ? to shorter, cleaner ones.

Some of it works fine but not the big things as I mentioned. If i look me up uing a newly created php-file with only in it an then run it in a browser it actually tells me that (in two plaes): _SERVER[“HTTP_ACCEPT_ENCODING”] gzip,deflate,sdch and _ENV[“HTTP_ACCEPT_ENCODING”] gzip,deflate,sdch so i guess it is supported but I havent made the right code or something.

Anyone that solved these kind o problems before?

2 Answers
2

My advice to you is not to worry about adding in the copious amount of .htaccess rules for forcing browser caching and setting correct expire time values for assets. If you download the W3 Total Cache plugin it handles adding all of the above into your .htaccess file for you.

If you would prefer not to install the caching plugin, I’ve taken the liberty of opening up my own sites .htaccess file and copying the optimisation rules and put them into a Github Gist for you.

Paste all of the code in the Gist at the top of your .htaccess file before the “# BEGIN WordPress” comment.

The Gist can be seen here.

Leave a Comment