Permanent 301 redirection of non www domains to www domains

How to redirect your domain to domain with www prefixed

redirection of your domain ( name to is very useful and must be done. Reason for this is that when you have a non redirected domain name then search engines will see and as two separate websites. Hence you will lose much of the website traffic due to this.

One of the simplest solution for this is to add a .htaccess file and permanently redirect your domain name to www prefiixed domain name. Here’s how to do it step by step:

  1. Create a file with name ‘.htacess’
  2. Add the following code to it:
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} !^$ [NC]
    RewriteRule ^(.*)$$1 [L,R=301]
  3. replace the ‘’ with your domain name
  4. upload this file to your web servers root folder

Thats it. You are done. You can check the redirection by typing your domain name in the browser without www prefix.

Note: Above told method only works for apache web servers. For IIS servers I recommend reading

Hope this tip will help you! cheers!

Asset Management in CodeIgntier

This is a quick tip, I wanna share with you all.

many of you must be using CodeIgniter for development of web apps. And I know everyone of you must have faced the problem of asset management (css, JS, images) in Codeigntier. Well here’s a quick tip for it and making it hassle free.

use of base tag in head section

First of all place all your files in some folder, this is how I use it. I always create three folders viz. css, images and js in root folder of codeigniter app. Then add following in head section

<base href=”<?php echo base_url(); ?>” />

After this, u can use only partial links in all you linking relative to you base href’s property!

For eg.

<script src=”js/jquery.min.js”></script>

and thats all, You won’t have to include base_url all the time in your codes for linking. It can be used for everything like images, scripts, css files etc.

Hope you find it useful!