2. Prepare a URL mapping

30/11/2019

It's important to map your old site's URLs to the URLs for the new site. This section describes a number of general approaches you can take to correctly assess the URLs on your two sites and facilitate mapping. The exact details of how you generate this mapping will vary depending on your current website infrastructure and the details of the site move.

Determine your current URLs

In the simplest of site moves, you may not need to generate a list of your current URLs. For example, you could use a wildcard server-side redirect if you’re changing just your site’s host (e.g. moving from example.com to example.net).

In more complex site moves, you will need to generate a list of old URLs and map them to their new destinations. How you get a listing of old URLs depends on your current website’s configuration, but here are some handy tips:

  • Start with your important URLs. To find them:
    • Look in your sitemaps because it's likely your most important URLs have been submitted in Search Console that way
    • Check your server logs or analytics software for the URLs that get the most traffic
    • Check the Links to your site feature in Search Console for pages that have internal and external links
  • Use your content management system, which can typically provide an easy way to get a listing of all URLs that host content.
  • Check your server logs for URLs that were visited at least once recently. Pick a time period that makes sense for your site, keeping in mind seasonal variation of traffic.
  • Include images and videos—Make sure that you include URLs of embedded content in your site move plans: videos, images, JavaScript, and CSS files. These URLs need to be moved in the same way as all other content on your website.

Create a mapping of old to new URLs

Once you have the listing of old URLs, decide where each one should redirect to. How you store this mapping depends on your servers and the site move. You might use a database, or configure some URL rewriting rules on your system for common redirect patterns.

Update all URL details

Once you have your URL mapping defined, you'll want to do three things to get the final URL mappings ready for the move.

  1. Update annotations in the HTML or sitemaps entry for each page:
    1. Each destination URL should have a self-referencing rel="canonical" LINK tag.  
    2. If the site you moved has multilingual or multinational pages annotated using rel-alternate-hreflang annotations, be sure to update the annotations to use the new URLs.
    3. If the site you moved has a mobile counterpart, make sure you update the rel-alternate-media annotations. Learn more in our smartphone websites guidelines.
  2. Update internal links
    Change the internal links on the new site from the old URLs to the new URLs. You can use the mapping generated earlier to help find and update the links as needed.
     
  3. Create and save sitemap and link lists
    Save the following lists for your final move:
    1. A sitemap file containing the new URLs in the mapping
    2. A sitemap file containing the old URLs in the mapping
    3. A list of sites linking to your current content

    Learn more about sitemaps.

Prepare for 301 redirects

Once you have a mapping and your new site is ready, the next step is to set up HTTP 301 redirects on your server from the old URLs to the new URLs as you indicated in your mapping.

Keep in mind the following:

  • Use HTTP 301 redirects. Although Googlebot supports several kinds of redirects, we recommend you use HTTP 301 redirects if possible.
  • Avoid chaining redirects. While Googlebot and browsers can follow a "chain" of multiple redirects (e.g., Page 1 > Page 2 > Page 3), we advise redirecting to the final destination. If this is not possible, keep the number of redirects in the chain low, ideally no more than 3 and fewer than 5. Chaining redirects adds latency for users, and not all browsers support long redirect chains.
  • Test the redirects. You can use Fetch as Google for testing individual URLs or command line tools or scripts to test large numbers or URLs.

* Nguồn: Google Search Console