HTACCESS is one of the most important files of a website. If its coded correctly then it can improve the load time of your website to the best possible limit. But if its coded incorrectly then you will keep messing with other PHP and HTML code, and your website speed will not improve. Once you have coded HTACCESS correctly you will also make it better according to SEO point of view.
However this is a blogger blog but i am providing tips for a wordpress website. just because this thing will help a number of people struggling with their Wordpress website. If you are aware of HTACCESS file then you must know its importance as well.
Below we will provide some coding for HTACCESS and also explain its use.
1) Add Expires : It will add a expiry tag to each type of file that the website loads while loading it in the browser of a user. If the same user access the same website again or go through the other pages of your website then the same content like images, logo, scripts, style sheets will not load again if expiry tags are added to it. Thus it improves the loading time of a website.
<IfModule mod_rewrite.c>
ExpiresActive On
# Default directive
ExpiresDefault "access plus 1 month"
# My favicon
ExpiresByType image/x-icon "access plus 1 year"
# Images
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
# CSS
ExpiresByType text/css "access plus 1 month"
ExpiresByType text/html "access plus 5 minute"
</IfModule>
2) Pagespeed Module for Apache Server Based Sites
<IfModule pagespeed_module>
ModPagespeed on
# using commands,filters etc
</IfModule>
3) ETag : Entity Tag tells if the content available in browser is same as file on the server. Thus it saves loading time of same content again. So it should be handled properly.
Header unset ETag
FileETag None
4) DEFLATE : If you know the zip files then you will understand it. Using DEFLATE make your website server send the zip version of files from server to browser which reduces the loading time a lot.
<IfModule mod_deflate.c>
# Insert filters
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/x-httpd-php
AddOutputFilterByType DEFLATE application/x-httpd-fastphp
AddOutputFilterByType DEFLATE image/svg+xml
# Drop problematic browsers
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
<FilesMatch ".(js|css|html|htm|php|xml)$">
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>
5) Multiple Connections: This will help your website in creating multiple connection with browser at the same time. Thus your wordpress website will improve.
<ifModule mod_headers.c>
Header set Connection keep-alive
<FilesMatch "\.(js|css|xml|gz)$">
Header append Vary: Accept-Encoding
</FilesMatch>
</ifModule>
Note: Before implementing these codes in your wordpress website HTACCESS code, make you that you have taken backup of your original HTACCESS. It will help you if anything goes wrong. I will suggest you to implement these changes one by one. Don't add all of the above codes at onces. Instead apply them one by one and also keep checking if your website is working or not. If anything goes wrong then revert the changes and add the next code.
Usually i use GTMETRIX to check performance of my websites. You can also use it as its a free tool. Check you website rating using it before applying the changes and then after applying the changes.
You are most welcome to add your comments about HTACCESS. Any suggestions are most welcome.
Best HTACCESS for Wordpress Website
However this is a blogger blog but i am providing tips for a wordpress website. just because this thing will help a number of people struggling with their Wordpress website. If you are aware of HTACCESS file then you must know its importance as well.
Below we will provide some coding for HTACCESS and also explain its use.
1) Add Expires : It will add a expiry tag to each type of file that the website loads while loading it in the browser of a user. If the same user access the same website again or go through the other pages of your website then the same content like images, logo, scripts, style sheets will not load again if expiry tags are added to it. Thus it improves the loading time of a website.
<IfModule mod_rewrite.c>
ExpiresActive On
# Default directive
ExpiresDefault "access plus 1 month"
# My favicon
ExpiresByType image/x-icon "access plus 1 year"
# Images
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
# CSS
ExpiresByType text/css "access plus 1 month"
ExpiresByType text/html "access plus 5 minute"
</IfModule>
2) Pagespeed Module for Apache Server Based Sites
<IfModule pagespeed_module>
ModPagespeed on
# using commands,filters etc
</IfModule>
3) ETag : Entity Tag tells if the content available in browser is same as file on the server. Thus it saves loading time of same content again. So it should be handled properly.
Header unset ETag
FileETag None
4) DEFLATE : If you know the zip files then you will understand it. Using DEFLATE make your website server send the zip version of files from server to browser which reduces the loading time a lot.
<IfModule mod_deflate.c>
# Insert filters
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/x-httpd-php
AddOutputFilterByType DEFLATE application/x-httpd-fastphp
AddOutputFilterByType DEFLATE image/svg+xml
# Drop problematic browsers
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
<FilesMatch ".(js|css|html|htm|php|xml)$">
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>
5) Multiple Connections: This will help your website in creating multiple connection with browser at the same time. Thus your wordpress website will improve.
<ifModule mod_headers.c>
Header set Connection keep-alive
<FilesMatch "\.(js|css|xml|gz)$">
Header append Vary: Accept-Encoding
</FilesMatch>
</ifModule>
Note: Before implementing these codes in your wordpress website HTACCESS code, make you that you have taken backup of your original HTACCESS. It will help you if anything goes wrong. I will suggest you to implement these changes one by one. Don't add all of the above codes at onces. Instead apply them one by one and also keep checking if your website is working or not. If anything goes wrong then revert the changes and add the next code.
Usually i use GTMETRIX to check performance of my websites. You can also use it as its a free tool. Check you website rating using it before applying the changes and then after applying the changes.
You are most welcome to add your comments about HTACCESS. Any suggestions are most welcome.
No comments:
Post a Comment