Thursday, March 21, 2013

301 Redirection, Leverage Browser Caching & Gzip Compression .htaccess Code

Web page speed is an important aspect of high search engine ranking. Google give high priority to page speed signals among 200 other signals. So i am going to share the code that is used to enhance the page speed of website.

301 is the permanent redirection from old url to new url. We can use 301 redirection code in .htaccess to resolve the issue of WWW and without (WWW). Suppose i have a website opening with both WWW and without WWW then search engine's will count them two different domains and the result will be duplicacy of two domains. We can resolve this issue with two methods either by setting our preferred domain in Google webmaster or by using 301 redirection.

Here is the method to set up a preferred domain in Google Webmaster.

  1. Login to Google.com/Wembasters
  2. Select the website you want to prefer.
  3. Go to setting
  4. Select preferred domain
  5. Select their either with WWW or without WWW.
After this the preferred domain will be set for all backlinks.

Here is the code of 301 redirection

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^example.com [nc]
rewriterule ^(.*)$ http://www.example.com/$1 [r=301,nc]

If you wish to set a Error status code for all Not found pages then use the following code:-

ErrorDocument 404 /errors/index.html

Here is the Gzip Compression code to compress the txt, html and css of webpages.

# compress text, html, javascript, css, xml:

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


#Gzip

AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript text/javascript

#End Gzip

Here is the code of leverage browsing cache. Leverage browsing cache is the process of remembering the images and other changeable things for next time visit of same visitors.

## EXPIRES CACHING ##

ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/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 2 days"

## EXPIRES CACHING ##

I love to hear from you and follow me on facebook to stay up to date.

Guaranteed Top Rankings in Google



No comments:

Post a Comment

Please don't leave link in comment....