What is the best way to do a 301 redirect with a delay of several seconds? I want the original page to be displayed for 5-10 seconds and then do a 301 redirect to another site. I'开发者_如何转开发ve found a lot of solutions in PHP on google but the only one I found with a delay didn't display the original page before redirecting—only an empty screen.
You're being redirected
<META HTTP-EQUIV="refresh" CONTENT="5;URL=the-other-page.html">
or in PHP
header( 'refresh: 5; url=/the-other-page.html' );
echo 'You\'re being redirected';
It is better to choose second solution, though
You can't really do a true 301 redirect with a delay. HTTP is stateless. For a "301 redirect", which is what you want if you're trying to make google happy; the client sends a request, and the status code on the reply from the server will be 301, also as part of the reply you'll use a location header and tell where the new content is. If you don't have all that, you're not doing a 301 redirect.
With the other answer, you're doing a meta refresh on the client side, which google does not like.
This is how you do a 301, and the user doesn't even see the old page at all, and probably will have no idea they've even been redirected.
$location="http://www.yoursite.com/newpage";
header ('HTTP/1.1 301 Moved Permanently');
header ('Location: '.$location);
If you are not the coding type, but you want an amazingly versatile free tool, I endorse Quick Pagepost Redirect Plugin
https://wordpress.org/plugins/quick-pagepost-redirect-plugin/
In this case you want to use a meta redirect.
This plugin can handle Wordpress redirects and meta redirects (in case you need a delay)
It supports 301, 302, 307, and meta redirects. You can add URL's to avoid 404's also.
If you are upgrading a site and changing page urls and wish to preserve seo ranking, this is the tool my friend uses (he's a pro)
This will do it all - no coding.
Disclaimer: I am not affiliated with these guys in any way.
精彩评论