简体   繁体   中英

Redirecting a page via javascript

It seems like it's more appropriate to use a meta redirect:

<meta http-equiv="refresh" content="0;url=$new_url" />

but there's no page lag with a javascript redirect (in the header)

document.location.href = $new_url;

My question is, which has the best payoff? I don't actually want SEO to ignore this page, I just want the user to be redirected if they ever get here. Which should I do?

SEO-friendly redirects send a HTTP response code of 301 or 302 (moved permanently). You cannot send a 301 response via javascript. The page will load, giving a 200 "page found" response, then it will run the javascript. Plus, I'm not sure search engines follow javascript re-directs.

Meta-tags are also not best for SEO. The page loads (giving a 200 "page found") then a new page is loaded. SEO benefits are lost.

Best to use server side redirects to be SEO friendly. You can do so using an .htaccess file on an Apache web server.

Here are some best practices for SEO-friendly redirecting:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM