Redirecting Based On Subdomains

I am fairly new to yii. If anyone enters a subdomain on www.mysite.com, such as fred.mysite.com or kelly.mysite.com I want to redirect them to a login page. I have already set up the wildcard domain on the server and DNS. My question is, where should I do the url work in Yii? Basically on every request I want to check for a subdomain and redirect to the login page if there is a subdomain. If there is no subdomain, I will not take any extra action. Should I extend the CUrlManager? Also, at what point should I run my check?

I think I may have found what I was looking for here, using onBeginRequest