Hello all - I earlier posted something on this, but was probably not clear enough with what I am looking for. I have looked in many places, but have not found how to redirect all "http://domain.com" to "http://www.domain.com", if the site is php based. This site is an add-on domain to my other site. Using C-Panel doesn't seem possible, as I can't see anything set up re: the add-on domain within the redirect tools. I did do a redirect for my main domain (thanks, Minstrel), after mucking about with the .htaccess Options in the _vti_bin folders (I have FP on my main site, and needed to alter the options for FP to work with the redirect in .htaccess). Now, the add-on domain has the following: The .htaccess file in the public_html only contains the following: DirectoryIndex index.php The index.php file begins with: <?php require_once '_db_interface.php'; ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> Can someone please provide some advice, given that index is a .php file? Thanks. Paul
You'll have to check if you have to redirect (http://domain.com) before you sent any output to the browser. I suppose there is a server/environment variable for this, check php.net. (maybe $_SERVER['HTTP_HOST'] is a good one) After this, you have to use the header() function to sent the redirect to the browser.
TMan, and others - I tried various header schemes, all of which returned errors. Being an asbolute noob, I don't really know what you are speaking of when you're talking about: But I am guessing what you are saying is that I have to put in the above server variable as a first line in index.php, followed by the header redirect, in order for the header redirect to work, correct? (maybe this is why I kept getting the errors...?) Nevertheless, I tried this: Inside root .htaccess: after DirectoryIndex index.php I added: RewriteEngine on RewriteCond %{HTTP_HOST} !^www RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [L,R=301] - and the redirect seems to be working. Is there any reason (security or otherwise) this wouldn't be a preferred method? Anyone? Thanks.
does anyone knows how to do this in windows 2003 with asp? i want respective page to go to respective page, like domainname.com/yahoo.html to www.domainname.com/yahoo.html