A common question but I only know how to do it in htaccess. I've been informed that my server is running in PHP Suexec mode so I can't use htaccess to redirect domain.com to www.domain.com. I know I need to create a php.ini file in my public_html directory but I'm not sure of the code. I had a lot of trouble finding anything about it in Google (almost all hits were about how to do it in htaccess) and anything I did find didn't appear to work. Thanks in advance.
if(strpos($_SERVER['HTTP_HOST'], "www.") !== 0){ header("Location: http://www." . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); } PHP: That ought to do it Might not be the best idea to let them specify the HOST they want to go to, so if you want, you can do it like this as well: $site = "mysite.com"; if(strpos($_SERVER['HTTP_HOST'], "www.") !== 0){ header("Location: http://www." . $site . $_SERVER['REQUEST_URI']); } PHP:
So I don't need the php.ini file? Someone at cpanel support told me I need a php.ini file in the public_html folder.
If you have direct access to apache its better to take care of this sort of thing there. Create an alias and have it redirect to www... This sort o f thing doesnt really belong inside the application in my opinion (but hey thats just me ) Hope this helps
Yes I have direct access to apache but I'm not quite sure what you mean by creating an alias there...
$site = "mysite.com"; if(strpos($_SERVER['HTTP_HOST'], "www.") !== 0){ header("Location: http://www." . $site . $_SERVER['REQUEST_URI']); } PHP: Dump that in an include file and remember to include it on every one of your pages