Redirect all to a www page

2006 Aug 18

In apache, we can redirect pages having no www to its www counterpart without manualy adding the www on the url by using mod_rewrite. Like for example, try to type in my url as tildemark.com on your browser's address bar, hit Enter and automatically you will be redirected to https://tildemark.com. This is useful to avoid duplicate caching of pages and the division of your pages' PR.

We need to edit our .htaccess file to add the 301 redirect.


# .htaccess file
# we need to check if mod_rewrite has been enabled, 
# by default its not

  RewriteEngine On
  RewriteCond %{HTTP_HOST}       ^tildemark.com
  RewriteRule (.*)               https://tildemark.com/$1 [R=301,L] 

Replace tildemark.com to your respective domain name. here's a mod_rewrite cheatsheet from ilovejackdaniels.com

Notes:
301 is an http status code meaning permanent redirect
.htaccess files should be placed on the root directory
PR is PageRank

Tweet this post

Leave a comment


About Me


Alfredo Sanchez is an internet professional focusing on the study search engines behavior in particular. Supports Free Open Source Software and currently develops applications with it using XAMPP.

Recent Entries

Close