php中的全局重定向从something.com到www.something.com

I'm a .net developer and I've just started developing a site on PHP running on IIS7-fastcgi.

I was wondering if there is any way to write a global function to automatically redirect any request that comes to my site in the format

http://something.com/anypage.php 
to
http://www.something.com/anypage.php

You can do this in ASP.NET on the global.asax file. IS there any way to do this or set this condition in php?

I don't think so..but you can do this using .htaccess

(edited to include comment below):

or the iis7 equivalent I guess is what you want http://learn.iis.net/page.aspx/557/translate-htaccess-content-to-iis-webconfig/

You can do this in IIS by using the URL Rewrite module.

Yes, you must have .htaccess in your root directory, that says :

Redirect 301 http://something.com/anypage.php  http://www.something.com/anypage.php 

But im not sure if IIS supports .htaccess files :)

if ($_SERVER['HTTP_HOST'] == "something.com") {
    header("Status: 301 Moved Permanently");
    header("Location: http://www.something.com" . $_SERVER['REQUEST_URI']);
    exit;
}