Home › Forums › BulletProof Security Free › WP Super Cache – WP Super Cache htaccess code, Custom Code
- This topic has 82 replies, 8 voices, and was last updated 8 years ago by
AITpro Admin.
-
AuthorPosts
-
AITpro Admin
KeymasterI played around with variations of ETag .htaccess code and I did not find any benefit from using it. And from looking around the Internet I do not think you should use this code. There is conflicting information about using this code. Use it at your own risk. If you are going to experiment with that code it needs to be in your root .htaccess file AFTER WP Super Cache .htaccess code. You would put this code in the
Also I ran into one minor issue with WP Super Cache, which I am still looking into. 2 pages were displaying blank so what I have now done is setup Garbage Collection in WP Super Cache to delete expired cached pages after 1 hour.
On the WP Super Cache Advanced page
Expiry Time & Garbage Collection
Cache Timeout: set to 3600 seconds which is 1 hour
Scheduler: chose Timer and set to 3600 seconds
Notification Emails: chose not to have emails sent to me when the garbage collection runs.Young Master
ParticipantI think the following codes works well if browser compression is enabled.
# A2592000 = 30 days # A86400 = 1 day ExpiresActive On ExpiresByType image/gif A2592000 ExpiresByType image/jpeg A2592000 ExpiresByType image/jpg A2592000 ExpiresByType image/png A2592000 ExpiresByType image/x-icon A2592000 ExpiresByType text/css A86400 ExpiresByType text/javascript A86400 ExpiresByType application/x-shockwave-flash A2592000 # <FilesMatch "\.(gif|jpe?g|png|ico|css|js|swf)$"> Header set Cache-Control "public" </FilesMatch>
So for me I would recommend the following:
# BEGIN Browser Cache <IfModule mod_mime.c> AddType text/css .css AddType text/x-component .htc AddType application/x-javascript .js AddType application/javascript .js2 AddType text/javascript .js3 AddType text/x-js .js4 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 application/vnd.ms-fontobject .eot AddType application/x-msdownload .exe AddType image/gif .gif AddType application/x-gzip .gz .gzip AddType image/x-icon .ico AddType image/jpeg .jpg .jpeg .jpe AddType application/json .json AddType application/vnd.ms-access .mdb AddType audio/midi .mid .midi 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/x-font-otf .otf AddType application/vnd.oasis.opendocument.database .odb AddType application/vnd.oasis.opendocument.chart .odc AddType application/vnd.oasis.opendocument.formula .odf AddType application/vnd.oasis.opendocument.graphics .odg AddType application/vnd.oasis.opendocument.presentation .odp AddType application/vnd.oasis.opendocument.spreadsheet .ods AddType application/vnd.oasis.opendocument.text .odt AddType audio/ogg .ogg 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 application/x-font-ttf .ttf .ttc 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> ExpiresActive On ExpiresByType text/css A31536000 ExpiresByType text/x-component A31536000 ExpiresByType application/x-javascript A31536000 ExpiresByType application/javascript A31536000 ExpiresByType text/javascript A31536000 ExpiresByType text/x-js A31536000 ExpiresByType text/html A3600 ExpiresByType text/richtext A3600 ExpiresByType image/svg+xml A3600 ExpiresByType text/plain A3600 ExpiresByType text/xsd A3600 ExpiresByType text/xsl A3600 ExpiresByType text/xml A3600 ExpiresByType video/asf A31536000 ExpiresByType video/avi A31536000 ExpiresByType image/bmp A31536000 ExpiresByType application/java A31536000 ExpiresByType video/divx A31536000 ExpiresByType application/msword A31536000 ExpiresByType application/vnd.ms-fontobject A31536000 ExpiresByType application/x-msdownload A31536000 ExpiresByType image/gif A31536000 ExpiresByType application/x-gzip A31536000 ExpiresByType image/x-icon A31536000 ExpiresByType image/jpeg A31536000 ExpiresByType application/json A31536000 ExpiresByType application/vnd.ms-access A31536000 ExpiresByType audio/midi A31536000 ExpiresByType video/quicktime A31536000 ExpiresByType audio/mpeg A31536000 ExpiresByType video/mp4 A31536000 ExpiresByType video/mpeg A31536000 ExpiresByType application/vnd.ms-project A31536000 ExpiresByType application/x-font-otf A31536000 ExpiresByType application/vnd.oasis.opendocument.database A31536000 ExpiresByType application/vnd.oasis.opendocument.chart A31536000 ExpiresByType application/vnd.oasis.opendocument.formula A31536000 ExpiresByType application/vnd.oasis.opendocument.graphics A31536000 ExpiresByType application/vnd.oasis.opendocument.presentation A31536000 ExpiresByType application/vnd.oasis.opendocument.spreadsheet A31536000 ExpiresByType application/vnd.oasis.opendocument.text A31536000 ExpiresByType audio/ogg A31536000 ExpiresByType application/pdf A31536000 ExpiresByType image/png A31536000 ExpiresByType application/vnd.ms-powerpoint A31536000 ExpiresByType audio/x-realaudio A31536000 ExpiresByType image/svg+xml A31536000 ExpiresByType application/x-shockwave-flash A31536000 ExpiresByType application/x-tar A31536000 ExpiresByType image/tiff A31536000 ExpiresByType application/x-font-ttf A31536000 ExpiresByType audio/wav A31536000 ExpiresByType audio/wma A31536000 ExpiresByType application/vnd.ms-write A31536000 ExpiresByType application/vnd.ms-excel A31536000 ExpiresByType application/zip A31536000 </IfModule> <IfModule mod_deflate.c> <IfModule mod_headers.c> Header append Vary User-Agent env=!dont-vary </IfModule> AddOutputFilterByType DEFLATE text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/html text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon application/json <IfModule mod_mime.c> # DEFLATE by extension AddOutputFilter DEFLATE js css htm html xml </IfModule> </IfModule> <FilesMatch "\.(css|htc|js|js2|js3|js4|CSS|HTC|JS|JS2|JS3|JS4)$"> <IfModule mod_headers.c> Header set Pragma "public" Header append Cache-Control "public" </IfModule> </FilesMatch> <FilesMatch "\.(html|htm|rtf|rtx|svg|svgz|txt|xsd|xsl|xml|HTML|HTM|RTF|RTX|SVG|SVGZ|TXT|XSD|XSL|XML)$"> <IfModule mod_headers.c> Header set Pragma "public" Header append Cache-Control "public" </IfModule> </FilesMatch> <FilesMatch "\.(asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|eot|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|json|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|otf|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|tif|tiff|ttf|ttc|wav|wma|wri|xla|xls|xlsx|xlt|xlw|zip|ASF|ASX|WAX|WMV|WMX|AVI|BMP|CLASS|DIVX|DOC|DOCX|EOT|EXE|GIF|GZ|GZIP|ICO|JPG|JPEG|JPE|JSON|MDB|MID|MIDI|MOV|QT|MP3|M4A|MP4|M4V|MPEG|MPG|MPE|MPP|OTF|ODB|ODC|ODF|ODG|ODP|ODS|ODT|OGG|PDF|PNG|POT|PPS|PPT|PPTX|RA|RAM|SVG|SVGZ|SWF|TAR|TIF|TIFF|TTF|TTC|WAV|WMA|WRI|XLA|XLS|XLSX|XLT|XLW|ZIP)$"> <IfModule mod_headers.c> Header set Pragma "public" Header append Cache-Control "public" </IfModule> </FilesMatch> # END Browser Cache
Young Master
ParticipantOr what do you think about this @AITPro Admin?
AITpro Admin
KeymasterLooks good to me.
Young Master
ParticipantI would like to exclude register and login pages from being cached by wp super cache. can you show me how to do that please.
AITpro Admin
KeymasterWP Super Cache does NOT cache the login page by default. If you look at the WP Super Cache Advanced tab page you will see these 2 default rules to not cache any files that start with wp- and the index.php file.
wp-.*\.php
index\.phpRegister is an action query on the wp-login.php page. The rule above does not cache the wp-login.php file and will not cache the register action.
/wp-login.php?action=register
AITpro Admin
KeymasterThis caching code is working very, very nicely in this Forum. We are currently not using a caching plugin in this Forum and are only using the is caching code below. Eventually WP Super Cache will be installed and configured in this BuddyPress Forum site.
You can find this .htaccess code and other cool .htaccess code on the http://www.askapache.com website. NOTE: This code below has been modified/changed from the example you will find on the askapache.com site.
# BEGIN Browser Cache # # ETag Header unset ETag FileETag None # Turn on Expires and set default to 0 ExpiresActive On ExpiresDefault A0 # Set up caching on media files for 1 year <FilesMatch "\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav)$"> ExpiresDefault A29030400 Header append Cache-Control "public" </FilesMatch> # Set up caching on media files for 2 months <FilesMatch "\.(gif|jpg|jpeg|png|swf)$"> ExpiresDefault A4838400 Header append Cache-Control "public" </FilesMatch> # Set up caching on js and css files 1 month <FilesMatch "\.(js|css)$"> ExpiresDefault A2419200 Header append Cache-Control "public" </FilesMatch> # Set up caching on commonly updated files for 1 day <FilesMatch "\.(txt|html)$"> ExpiresDefault A86400 Header append Cache-Control "proxy-revalidate" </FilesMatch> # Force no caching for dynamic files <FilesMatch "\.(php|cgi|pl|htm|xml)$"> ExpiresActive Off Header set Cache-Control "private, no-cache, no-store, proxy-revalidate, no-transform" Header set Pragma "no-cache" </FilesMatch> # # END Browser Cache # mod_deflate AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
Time cheat sheet
A0 = no seconds/no time / variable value = blank/no value
60 seconds = A60
1 hour = 60 seconds x 60 minutes = 3600 seconds = A3600
2 hours = 60 seconds x 120 minutes = 7200 seconds = A7200
1 day/24 hours = 24 x 3600 (1 hour) = 86400 seconds = A86400
1 week/7 days = 7 x 86400 (1 day) = 604800 seconds = A604800
2 weeks = 2 x 604800 (1 week) = 1209600 seconds = A1209600
4 weeks/1 month = 4 x 604800 (1 week) = 2419200 seconds = A2419200
2 months = 2 x 2419200 (1 month) = 4838400 seconds = A4838400
3 months = 3 x 2419200 (1 month = 7257600 seconds = A7257600
6 months = 6 x 2419200 (1 month) = 14515200 seconds = A14515200
1 year = 2 x 14515200 (6 months) = 29030400 seconds = A29030400Young Master
ParticipantI see. Do you think WP Super Cache works better than W3 Total Cache?
AITpro Admin
KeymasterEach person should install, configure, test and benchmark each plugin to determine which caching plugin works better for them.
Young Master
ParticipantI would also like to recommend http: //wordpress.org/plugins/wp-smushit/ plugin. Its a great plugin for optimizing images. http: //smush.it/ offers an API that performs the following optimizations automatically, and this plugin seamlessly integrates Smush.it with WordPress.
- optimizing JPEG compression
- converting certain GIFs to indexed PNGs
- stripping the un-used colours from indexed images
AITpro Admin
KeymasterAfter months of experimentation and combatting ongoing issues/problems with caching plugins we are now ONLY using the .htaccess caching code above. It may cost a split second or two in page load time, but we would rather have everything working consistently at all times then have to deal with corrupt cache, blank pages and other various issues and problems with both WPSC and W3TC and some other caching plugins that we tried. 😉
silas88
ParticipantI have been working with htaccess caching also, and I found the askapache site a useful reference although the fact that it’s difficult to search and see the date of the articles is frustrating at times. There is a lot of stuff there that on further inspection (i.e. mostly reading the comments) turn out to be out of date / incorrect.
Re Etag – have you concluded that Etags should be removed?
I found that if I check my site with the very useful redbot.org that Etags are flagged as issues on images “The ETag doesn’t change between negotiated representations.”
This is the end part of my custom code section (excuse the long code section). From your comments above it seems I should move the caching elements to the top after the WPSC code. I found that it seems to work OK anyway.
# CUSTOM CODE BOTTOM HOTLINKING/FORBID COMMENT SPAMMERS/BLOCK BOTS/BLOCK IP/REDIRECT CODE # TIME CHEAT SHEET # 300 5 MIN # 600 10 MIN # 900 15 MIN # 1800 30 MIN # 2700 45 MIN # # 3600 1 HR # 7200 2 HR # 10800 3 HR # 14400 4 HR # 18000 5 HR # 36000 10 HR # 39600 11 HR # 43200 12 HR # 46800 13 HR # 50400 14 HR # 54000 15 HR # 86400 24 HR # # 86400 1 DAY # 172800 2 DAY # 259200 3 DAY # 345600 4 DAY # 432000 5 DAY # 518400 6 DAY # 604800 7 DAY # # 604800 1 WEEK <ifModule mod_expires.c> # any Expires Directives go here ExpiresActive On ExpiresDefault A86400 ExpiresByType image/gif A2592000 ExpiresByType image/jpeg A2592000 ExpiresByType image/jpg A2592000 ExpiresByType image/png A2592000 ExpiresByType image/x-icon A2592000 ExpiresByType text/css A86400 ExpiresByType text/javascript A2592000 # ExpiresByType application/x-shockwave-flash A2592000 ExpiresByType application/pdf A2592000 </ifModule> ### HEADER CACHING <ifModule mod_headers.c> # any Header directives go here # below from http://www.askapache.com/htaccess/apache-speed-cache-control.html #Header unset Pragma #FileETag None #Header unset ETag # below from http://www.askapache.com/htaccess/speed-up-sites-with-htaccess-caching.html <FilesMatch "\.(flv|gif|jpg|jpeg|png|ico|woff)$"> Header set Cache-Control "max-age=2592000" </FilesMatch> <FilesMatch "\.(js|css|pdf|swf)$"> Header set Cache-Control "max-age=604800" </FilesMatch> <FilesMatch "\.(html|htm|txt)$"> Header set Cache-Control "max-age=7200" Header append Cache-Control "private, must-revalidate" </FilesMatch> <FilesMatch "\.(pl|php|cgi|spl|scgi|fcgi)$"> # Header unset Cache-Control Header set Cache-Control "no-store, no-cache, must-revalidate, max-age=0" Header set Pragma "no-cache" </FilesMatch> <FilesMatch "\.(gif|jpe?g|png|ico|woff|js|swf)$"> Header append Cache-Control "public" </FilesMatch> </ifModule>
silas88
ParticipantThere are a few ways to use redbot, I found this particular method very useful as it gives further detail http: //redbot.org/?descend=True&uri=http://mydomain.com#
AITpro Admin
KeymasterTo tell you the truth I am not 100% sure about ETags. There is conflicting info around the Internet. Currently we are removing ETags. Whether this is the best thing to do I believe they should be removed, but that is just my opinion. It may also be a case by case thing that each person should test/benchmark to see what works best for their particular website/Server/Environment.
AITpro Admin
KeymasterOn a personal note, I am bummed out that page caching is not working out for our sites with caching plugins. We are looking into alternative methods to do this that work consistently. Or maybe a better more effecient way of detecting and deleting corrupted cached pages would be the solution. Having home pages and other very important pages displaying a blank white page for hours is something we just cannot have going on on our sites so at this point we cannot use any caching plugins and have to accept that the initial page load times on our sites will be increased as much as 1 second. ;(
Note: This may be a host specific thing and would not happen for other folks on other Hosts/Servers. We spent months trying every possible combination of settings and nothing seemed to stop blank white pages/corrupted page cache from randomly occurring except for one thing and that was to exclude the page from being cached. 😉
-
AuthorPosts
- You must be logged in to reply to this topic.