Jump to content

How to redirect example.com to www.example.com?


SandySynaptik

Recommended Posts

I not sure if this is right place to ask this question. I want to redirect the user from http://example.com to http://www.example.com Something like Google and Facebook does, if you go to facebook.com you will be redirected to www.facebook.com

Link to comment
Share on other sites

I not sure if this is right place to ask this question. I want to redirect the user from http://example.com to http://www.example.com Something like Google and Facebook does, if you go to facebook.com you will be redirected to www.facebook.com
put this at the top of index.php
<?	 if($_SERVER['SERVER_NAME'] == "example.com")		  header('Location: http://www.example.com');?>

Link to comment
Share on other sites

also if you want it to do it for any pageput this at the top of all pages.

<?	 $urlPrefix = substr($_SERVER['SERVER_NAME'], 0, 4);	 if($urlPrefix != 'www.')		  header('Location: http://www.' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']);?>

also you might want to look into .htaccessI am no help on that though I have a couple threads open on that.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...