Welcome to WebmasterWorld Guest from 220.127.116.11 , register , free tools , login , search , pro membership , help , library , announcements , recent posts , open posts Become a Pro Member
Redirect vs Forward iamvela
Is there a way to do PHP redirect, rather than PHP forward. When we post a link to http://example.com on Facebook etc. it shows the meta tags on our index page and not on the actual page. I'd really like for the actual page to be pre-viewed (as in loaded). The only explanation I can come up with is it has to do with doing a redirection as header(location: $url); I have tried to put a header( "HTTP/1.1 301 Moved Permanently" ); before the redirect but to no avail. Any ideas would be very much appreciated. Thanks. -- [ edited by: dreamcatcher at 4:42 am (utc) on May 25, 2010] [edit reason] Use example.com, thank you [/edit]
This is what we use: header("Location: http://example.com", TRUE, 302); If you want a 301 (permanent) use this: header("Location: http://example.com", TRUE, 301); Make sure you put this line before ANY content or whitespace is printed or you'll get an error. iamvela
Thats very helpful, when I tried that on a test.php file it works but once integrated with our code it still does not :( Admin can we pls share the actual URL? Matthew1980
Hi there iamvela, It would be helpful to post the portion of code you have placed the header into, because if it works in your 'test.php' there must be something wrong with where or how you have placed the header in the context of your actual script. And as KevinH correctly states, if there is anything (even whitespace) after the declaration, you will get an error. Usually if you are using a header(); it's a good method to kill the script directly after so that nothing downstream can be executed:- // //Rest of your code // header("Location: Someurl.com"); exit; Cheers, MRb TheMadScientist
When we post a link to http://example.com on Facebook etc. it shows the meta tags on our index page and not on the actual page. I'd really like for the actual page to be pre-viewed (as in loaded). Could you define 'doesn't work' a bit more? Is it working with the browser you are using? If it is not doing anything have you emptied your cache? Is it working with the browser and not FaceBook? If it is you will probably need to link directly to the page if possible, because my guess is it's FB's system rather than the PHP redirect. IOW: If you empty your cache and the browser redirects without PHP throwing a 'header already set' error, then it's a FaceBook issue, not a PHP issue.