Mod_rewrite: August 2006 Archives

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 http://www.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
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{HTTP_HOST}       ^tildemark.com
  RewriteRule (.*)               http://www.tildemark.com/$1 [R=301,L] 
</IfModule>

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

About this Archive

This page is a archive of entries in the Mod_rewrite category from August 2006.

Mod_rewrite: September 2006 is the next archive.

Find recent content on the main index or look in the archives to find all content.

Recent Activity

Friday

  • tildemark tweeted, "im so sleepy. Zzzzzzzz"

Sunday

  • tildemark tweeted, "some of my scipts are not working with godaddy. but works fine on the others. not mention their poorly coded admin page"

Today

  • tildemark tweeted, "so many pending tasks i need to finish. need more coffee !!!"
  • tildemark tweeted, "@gmtristan i dont think that is true."

Today

  • tildemark tweeted, "how does godaddy subdomain behaves? i have some problems with it on my scripts. it does not seem to accept query strings.."

Monday

  • tildemark tweeted, "i had a hard time removing the error messages generated by surf side kick. i ended up uninstalling most of my applications."

Sunday

  • tildemark tweeted, "i got hit by surf side kick and im getting numerous error messages on my screen. tskkkkk"

Saturday

  • tildemark tweeted, "check boxes, i didn't know they can also be complex"
  • tildemark tweeted, "this smart bro internet speed is depressing, i thinking of filling a complaint to the DTI next week."

Friday

  • tildemark tweeted, "the seminar turned out to be leadership training. it was fun, learned alot. i have already attended numerous seminars but this is different."