简体   繁体   中英

Old to new 301 redirect parameters for better Google migration?

I have changed my domain name and redirecting every request to new domain with index.php like:

<?php
// Permanent redirection
$url = "http://newdomain.com".$_SERVER['REQUEST_URI'];
header("HTTP/1.1 301 Moved Permanently");
header("Location: ".$url);
exit();
?>

also with .htaccess like:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

I also made domain changing from Google Webmaster Tools. Should I add something or do sth more to this for better Google migration?

It looks like you're only redirecting requests to files/directories that don't exist. Static files (CSS, JS, images) won't be redirected. The following snippet will avoid PHP entirely and redirect ALL requests to your new domain:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ http://newdomain.com/$1 [R=301,L]
</IfModule>

To continue serving static files from the old domain, use:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://newdomain.com/$1 [R=301,L]
</IfModule>

Aside from redirects, make sure you update all links and file references on the new domain. You'll want to keep the redirects online for at least a few weeks to give them a chance to settle in. I also recommend getting in touch with anyone that may be linking to your site and ask that they update their link to reflect the domain change. Google's Webmaster Tools can help with this and identifying bad links.

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