Help Me Site Redirect

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
link2nayak
Forum Newbie
Posts: 1
Joined: Tue Mar 31, 2009 2:52 am

Help Me Site Redirect

Post by link2nayak »

Hi Friends,

I create my site http://www.padcilpharma.com its host on window server.

Its open with and without www.

I want its open with only www.

My host provider told me use phc scripting for that.


How am I do that...

Help
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Help Me Site Redirect

Post by requinix »

1) I can't get to your site.
2) What does "open" mean? "Accessible"?
3) Never heard of PHC.
User avatar
greyhoundcode
Forum Regular
Posts: 613
Joined: Mon Feb 11, 2008 4:22 am

Re: Help Me Site Redirect

Post by greyhoundcode »

Take a look at $_SERVER['REQUEST_URI'] and inspect it to see if it contains the 'www' prefix. If it doesn't, use header() to redirect.
User avatar
LanceEh
Forum Commoner
Posts: 46
Joined: Tue Feb 17, 2009 11:53 am
Location: Florida

Re: Help Me Site Redirect

Post by LanceEh »

Why not just use htaccess?
User avatar
greyhoundcode
Forum Regular
Posts: 613
Joined: Mon Feb 11, 2008 4:22 am

Re: Help Me Site Redirect

Post by greyhoundcode »

LanceEh wrote:Why not just use htaccess?
I assuming he isn't allowed to do this with his shared hosting account - "My host provider told me use phc scripting for that." (If phc is indeed PHP!) - though I guess that is an easier way to do it.
link2nayak wrote:
greyhoundcode wrote:Take a look at $_SERVER['REQUEST_URI'] and inspect it to see if it contains the 'www' prefix. If it doesn't, use header() to redirect.
I can't understand you.
You could have replied in this forum you know, rather than by PM. Not as if we're discussing state secrets or anything :wink:

Anyway, assuming you can't sort it via .htaccess like LanceEh says, what I was getting at was you could look at the contents of $_SERVER['REQUEST_URI'] (if this array element is accessible on your setup) and see if 'www.' is present in the address.

If it isn't, you can redirect the user using the header() function. If you're still unsure, take a look at the PHP manual's info on the $_SERVER array and its entry on the header() function.
Post Reply