Welcome to WebmasterWorld Guest from 54.211.17.91

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Redirect vs Forward

   
12:12 am on May 25, 2010 (gmt 0)

5+ Year Member



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]

5:19 am on May 25, 2010 (gmt 0)

5+ Year Member



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.
5:54 am on May 25, 2010 (gmt 0)

5+ Year Member



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?
7:32 am on May 25, 2010 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



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
2:54 pm on May 25, 2010 (gmt 0)

WebmasterWorld Senior Member themadscientist is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



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.