I have been trying to do a proper 301 redirect and have failed to do so. No matter what i try, its always a 302 redirect.
Returns a 302:
http_redirect("urlgoeshere", '', false, HTTP_REDIRECT_PERM)
Returns a 302:
header("HTTP/1.1 301 Moved Permanently");
header("Location: urlgoeshere");
Can anyone explain why these are coming back as 302's and not 301's? Server OS is linux, running PHP/5.2.14. Try it yourself.
I will give you guys a URL to try. I am testing using YSlow and Googlebot.
Should be 301: http://www.fantasysp.com/player/mlb/Albert_Pujols/1486349
The reasons for 301 redirect not working are much more well-defined among WordPress sites. One of the main causes is because you have added the rewrite rules on both the cPanel “Redirects” tool and from your WordPress plugin.
The Difference Between a 301 Redirect vs.301 redirects are permanent, whereas 302 redirects are temporary. A 301 is used when a page has permanently changed location, and a 302 should be used if you intend to move the page back under the original URL in the future.
To 301 Redirect an Entire Domain: Replace http://www.new-domain.com/ with the URL that you would like your site to redirect to. Be sure to add a blank line at the end of your . htaccess document. This signals to the server that it has reached the end of the .
Pretty straightforward actually:
header('Location: ' . $url, true, 301);
If you're using FastCGI try doing this instead:
header('Status: 301 Moved Permanently', true);
header('Location: ' . $url); // or header('Location: ' . $url, true, 301);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With