Website Programming

Force www. in your website url using .htaccess or httpd.conf
Force www. in your website url
It's never a good idea to have duplicates of the same page indexed by Google. Why’s that?

Because they will be placed into the Supplemental Index.


This means that you either have URLs that look like this: http://example.com/ or this: http://www.example.com/ Both URLs would go to the same page, but to a robot, they are different sites entirely and so one would appear as a duplicate of the other.

we will do that with two methods:

  • httpd.conf method
  • .htaccess method

first way using httpd.conf


edit the httpd.conf from
pico/etc/httpd/conf/httpd.conf
and shearch for :
usecanonicalname
and chage it from On to Off and save changes then restart the apache by service httpd restart.

second way using .htaccess

Insert this into the top of your .htaccess file, making sure that ‘RewriteEngine On’ comes before it:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.jooria.com [NC]
RewriteRule ^(.*)$ http://www.jooria.com/$1 [R=301,L]
Replace jooria.com with your chosen domain and make sure if you are placing any full stops within the first line to enter a backslash before each full stop. This will prevent the code from not working.
in: » Website Programming | Posted on Sep 7th, 2009 | last update on Jun 18th, 2010 | views 4,338
About the author
i'm moustafa from egypt i love doing one thing 'web programming & designing', This year I've got 19 years old and i'm in the english College of management (in Business Administration part soon)