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
# 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"
# 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 "\.(css)$">
    Header set Cache-Control "max-age=604800, public"
  <filesMatch "\.(js)$">
    Header set Cache-Control "max-age=216000, private"
  <filesMatch "\.(x?html?|php)$">
    Header set Cache-Control "max-age=600, private, must-revalidate"
# END Cache-Control Headers 

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

# BEGIN Remove Last-Modified Header 
<ifModule mod_headers.c>
  Header unset Last-Modified
# 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.*
# 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?


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.

| improve this answer | |
  • Wow, you guys here are far too kind :), actually I played aroun a bit with different Plugins but somehow I dont trust them and if I learn to do things manually I atually make progress in my job and career too! I will now look into your paste, be back later. – Emanuel Olsson Feb 20 '13 at 23:52
  • Also, begin wordpress? Do you mean that I should try to paste it at the very top of the document, before ETag setting or do you mean precisely after that and before # BEGIN Compress text files? And what should I now remove from my own settings? I guess some things will be overriden. Do you want me to paste it all, your paste + mine somewhere? – Emanuel Olsson Feb 21 '13 at 0:00
  • That is a great attitude to have as a developer Emanuel. Definitely better to understand how a plugin does something or read through someone else's code than not knowing. It's like how people proclaim to know Javascript but only know jQuery. – Dwayne Charrington Feb 21 '13 at 0:01
  • If you can put your file into a Github Gist and link to it I can help you out! – Dwayne Charrington Feb 21 '13 at 0:02
  • Coming right up! gist.github.com/geemoney/5000890 – Emanuel Olsson Feb 21 '13 at 0:14

I recommend using this as a base to start from, it is well commented and created by some great devs. You just have to paste it below the default WordPress created .htaccess, just comment out # Option 1 rewrites (line 365- 369).

It is part of the HTML5 Boilerplate framework


| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.