Jump to content

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


SandySynaptik
 Share

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

Edited by Sandy Synaptik
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.

Edited by dzhax
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...