How to redirect to WWW

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jonwondering
Forum Commoner
Posts: 39
Joined: Mon Mar 13, 2006 6:26 pm

How to redirect to WWW

Post by jonwondering »

Hi, I was wondering if it's possible to redirect the user from "http://mysite.com" to "http://www.mysite.com" ? Is there a way to do it?

Thanks,
jonwondering
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

header('Location: ....')

or if you're running Apache, mod_rewrite can do it.
jonwondering
Forum Commoner
Posts: 39
Joined: Mon Mar 13, 2006 6:26 pm

Post by jonwondering »

right, but if I just put it there by itself:

header('Location: http://www.mysite.com');

won't it just keep redirecting to itself forever? or at least something bad will happen? :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You'll have to write the code to figure out what domain the user is on.

Hint: look at $_SERVER
jonwondering
Forum Commoner
Posts: 39
Joined: Mon Mar 13, 2006 6:26 pm

Post by jonwondering »

oh yeah, i havent thought about checking domain... duh, lol. i was thinking about going into variables, but that'd be too messy
thanks feyd!
Post Reply