slj90 Posted November 4, 2012 Share Posted November 4, 2012 So I have a header('Location: ') in my script and it works fine if I enter something like header('Location: profile.php ') It will go to http://www.example.com/profile.php But I am trying to make it go to the homepage of the site which is just http://www.example.com. I don't want it to show index.php or default.php. So my question is what do I need to put in header('Location: ') for it to direct back to the homepage http://www.example.com Thanks Quote Link to comment Share on other sites More sharing options...
Zane Posted November 4, 2012 Share Posted November 4, 2012 Have you tried adding the http protocol to it? header("Location: http://www.example.com"); Quote Link to comment Share on other sites More sharing options...
trq Posted November 4, 2012 Share Posted November 4, 2012 Your first example is incorrect in the first place. A location header should always be set to a url. To get your second example working: header('Location: http://example.com'); Quote Link to comment Share on other sites More sharing options...
Adam Posted November 4, 2012 Share Posted November 4, 2012 You could also just use: header('Location: /'); Quote Link to comment Share on other sites More sharing options...
trq Posted November 5, 2012 Share Posted November 5, 2012 You could also just use: header('Location: /'); The location header requires a url according to the http spec, so it's always best to provide a complete url. Quote Link to comment Share on other sites More sharing options...
slj90 Posted November 5, 2012 Author Share Posted November 5, 2012 Thanks. I had only tried www.example.com which directed to www.example.com/www.example.com! But with http:// at the front it is working. Quote Link to comment Share on other sites More sharing options...
computermax2328 Posted November 5, 2012 Share Posted November 5, 2012 I was going to say, do you have the write file path. I always keep my pages in a lower folder than my index. So mine would look like: header('Location:../index.php'); Quote Link to comment Share on other sites More sharing options...
trq Posted November 5, 2012 Share Posted November 5, 2012 I was going to say, do you have the write file path. I always keep my pages in a lower folder than my index. So mine would look like: header('Location:../index.php'); This will be the third time I have mentioned this, but the Location header requires a url. Quote Link to comment Share on other sites More sharing options...
computermax2328 Posted November 5, 2012 Share Posted November 5, 2012 This will be the third time I have mentioned this, but the Location header requires a url. Not to step on your toes, but if that is true why does that work? I do it all the time. Quote Link to comment Share on other sites More sharing options...
trq Posted November 5, 2012 Share Posted November 5, 2012 Doing so means you are relying on a broken implementation. Most browsers implement it incorrectly. Quote Link to comment Share on other sites More sharing options...
Adam Posted November 5, 2012 Share Posted November 5, 2012 The location header requires a url according to the http spec, so it's always best to provide a complete url. Ah, I never realised that. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.