I have seen examples Apache htaccess file code where compression is before cache and visa versa. Which is correct? I use redbot.org quite a bit and it seems compressing after cache produces fewer issues.
You may compress with gzip compression in this way:
<ifModule mod_deflate.c>
<filesMatch ".(css|js|x?html?|php)$">
SetOutputFilter DEFLATE
</filesMatch>
</ifModule>
To cache files, you could do this:
<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>
To more informations, visit this page:
http://samaxes.com/2009/01/more-on-compressing-and-caching-your-site-with-htaccess/
Related
this is my htaccess cache-control policy:
<FilesMatch "\.(flv|gif|jpg|jpeg|png|ico)$"> Header set Cache-Control "max-age=31536000" </FilesMatch>
<FilesMatch "\.(js|css|pdf|swf)$"> Header set Cache-Control "max-age=31536000" </FilesMatch>
<FilesMatch "\.(html|htm|txt)$"> Header set Cache-Control "max-age=600" </FilesMatch>
<FilesMatch "\.(pl|php|cgi|spl|scgi|fcgi)$"> Header unset Cache-Control </FilesMatch>
<FilesMatch "\.(eot|otf|ttf|woff|woff2|svg)$"> Header set Cache-Control "max-age=31536000" </FilesMatch>
Now, for webp images is it possible to set a cache-control directive?
Thanks a lot
I have read about 10 different articles explaining how to write an .htaccess file. I've followed their explanations and put the .htaccess.txt file in the root directory. But still it won't redirect my site from non-www to www.
Here's my .htaccess file:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mecoder.co.il$ [NC]
RewriteRule ^(.*)$ http://www.mecoder.co.il/$1 [L,R=301]
<FilesMatch "\.(jpg|png)$">
Header set Cache-Control "public, max-age=321408000"
</FilesMatch>
<ifModule mod_headers.c>
ExpiresActive On
ExpiresDefault A86400
<FilesMatch "\.(ico|gif|jpg|jpeg\png|flv|pdf|swf|mov|mp3|wmv|ppt)$">
ExpiresDefault A1814400
Header append Cache-Control "public"
</FilesMatch>
<FilesMatch "\.(xml|txt|html)$">
ExpiresDefault A259200
Header append Cache-Control "proxy-revalidate"
</FilesMatch>
<FilesMatch "\.(js|css)$>
ExpiresDefault A10800
Header append Cache-Control "proxy-revalidate"
</FilesMatch>
<FilesMatch "\.(php|cgi|pl)$">
ExpiresDefault A0
Header set Cache-Control "no-store, no-cache, must revalidate, max-age=0"
Header set Pragma "no-cache"
</FilesMatch>
</IfModule>
<ifModule mod_deflate.c>
<FilesMatch "\.(js|css|html|htm|php|xml)$">
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)(\.gz)?$">
Header unset ETag
FileETag None
</FilesMatch>
And here is my site
First, it's not .htaccess.txt but .htaccess (without .txt).
If that doesn't work, you must check if overriding with .htaccess file is enabled in your server configuration. To do that, you should add AllowOverride All to your vhost or apache configuration.
present link http://www.easydownlink.com/profile.php?uid=105
i like to show this is as http://www.easydownlink.com/johny12 please give code for it
dudes this is my complete code in htaccess file. i confused where to add mod rewrite for friendly urls. please help me. please give ur valuble suggestions.
DirectoryIndex index.html index.php
Options -Indexes
<IfModule mod_headers.c>
# 1 YEAR
<FilesMatch "\.(ico|pdf|flv)$">
Header set Cache-Control "max-age=29030400, public"
</FilesMatch>
# 1 WEEK
<FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
# 2 DAYS
<FilesMatch "\.(xml|txt|css|js)$">
Header set Cache-Control "max-age=172800, proxy-revalidate"
</FilesMatch>
# 1 MIN
#<FilesMatch "\.(html|htm|php)$">
#Header set Cache-Control "max-age=60, private, proxy-revalidate"
#</FilesMatch>
</IfModule>
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 3 days"
ExpiresByType image/jpeg "access plus 3 days"
ExpiresByType image/gif "access plus 3 days"
ExpiresByType image/png "access plus 3 days"
</IfModule>
I have a file called xxx.php and in htaccess i have
<ifModule mod_deflate.c>
<filesMatch "\.(js|css|html|php)$">
SetOutputFilter DEFLATE
</filesMatch>
</ifModule>
how can i disable xxx.php file being cached?
Use a negative lookahead to exclude xxx.php:
<FilesMatch "^(?!xxx\.php$).*\.(js|css|html|php)$">
SetOutputFilter DEFLATE
</FilesMatch>
I input the following into my .htaccess file for www.localmarketingus.com
<ifModule mod_deflate.c>
<filesMatch "\.(css|js|x?html?|php|xml|html)$">
SetOutputFilter DEFLATE
</filesMatch>
</ifModule>
# BEGIN Turn ETags Off
<ifModule mod_headers.c>
Header unset Pragma
Header unset ETag
</ifModule>
FileETag None
# END Turn ETags Off
# BEGIN Compress text files
<ifModule mod_deflate.c>
<filesMatch "\.(css|js|x?html?|php|xml|html)$">
SetOutputFilter DEFLATE
</filesMatch>
</ifModule>
# END Compress text files
# BEGIN Expire Headers
<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 text/html "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 year"
ExpiresByType application/javascript "access plus 1 month"
ExpiresByType application/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 1 month"
</IfModule>
#END Expire headers
#BEGIN Vary Accept Encoding
<IfModule mod_headers.c>
<FilesMatch "\.(js|css|xml|gz)$">
Header append Vary: Accept-Encoding
</FilesMatch>
</IfModule>
#END Vary Accept Encoding
<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>
# 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 Remove Last-Modified Header
<ifModule mod_headers.c>
Header unset Last-Modified
</ifModule>
# END Remove Last-Modified Header
However, when i ran GTMetrix and PageSpeed insights it still said that i need to leverage browser caching and vary: accept encoding??
Is there something I did wrong in the code??
Thanks,
Please add this:
#BEGIN Vary Accept Encoding
<IfModule mod_headers.c>
<FilesMatch "\.(js|css|xml|gz)$">
Header append Vary Accept-Encoding
</FilesMatch>
<FilesMatch "\.(ico|jpe?g|png|gif|swf)$">
Header set Cache-Control "public"
</FilesMatch>
<FilesMatch "\.(css)$">
Header set Cache-Control "public"
</FilesMatch>
<FilesMatch "\.(js)$">
Header set Cache-Control "private"
</FilesMatch>
<FilesMatch "\.(x?html?|php)$">
Header set Cache-Control "private, must-revalidate"
</FilesMatch>
</IfModule>
#END Vary Accept Encoding
Instead of:
#BEGIN Vary Accept Encoding
<IfModule mod_headers.c>
<FilesMatch "\.(js|css|xml|gz)$">
Header append Vary: Accept-Encoding
</FilesMatch>
</IfModule>
#END Vary Accept Encoding
You can check out my website on gtmetrix to see I scored 100 % on the "Specify a Vary: Accept-Encoding header" test. This is my website: http://www.fotoshooting.ro/
Good luck!