Domains & Websites

How to Migrate a Website to a New Host Without Losing Data or SEO Rankings

By NileVPS Team · Published · 7 min read

اقرأ المقال بالعربي

Moving a website from one host to another worries a lot of site owners, and for good reason: one mistake can mean lost orders or messages, error pages for visitors arriving from Google, or a drop in rankings that took years to build. But a migration on its own does not hurt SEO, as long as your URLs and content stay the same and the site remains available throughout. In this guide we lay out a practical, proven plan that keeps the risk to a minimum, whether you are moving a WordPress site, a PHP application, or any site built on files and a database.

Step 1: Take Inventory and Plan

Before touching a single file, write down everything your site depends on:

  • Files: the site's code, uploaded images, and configuration files such as .env or wp-config.php.
  • Databases: the name, the engine (MySQL, MariaDB or PostgreSQL) and the version.
  • Software versions: the PHP or Node.js version, plus required extensions such as php-intl or php-gd.
  • Scheduled tasks (cron): any scripts that run automatically.
  • Email: is your email hosted on the same server? If so, you need a separate plan to move it, or to move it to a standalone email service.
  • Current DNS records: screenshot or copy every record (A, CNAME, MX and TXT) before changing anything.
  • SSL certificate: where it is issued from, and whether it will need to be reissued.

Also pick a low-traffic window for the final cutover, and ask your team to freeze content changes during the migration.

Step 2: Lower the TTL Early

The TTL on your DNS records determines how long networks keep the old address cached. If it is set to a full day, some visitors may keep reaching the old server for many hours after the switch.

At least a day or two before the move, lower the TTL on your domain's A records to a short value such as 300 seconds. You have to wait for the full old TTL to expire before the new value takes effect.

Step 3: Take a Full Backup

Make a complete copy of the files and the database and store it somewhere other than either server, such as your own computer or external storage.

# Compress the site files on the old server
tar -czf site-files.tar.gz -C /var/www example.com

# Export the database
mysqldump -u dbuser -p --single-transaction --routines --triggers dbname > db.sql

If you are on shared hosting without SSH, use the backup tools in your control panel and the phpMyAdmin export, and be sure to open the resulting files to confirm they are complete.

Step 4: Prepare the New Server

Set up the new server with the same environment, or a compatible one: the web server, the same PHP version or a newer compatible one, and the database. If you are moving to a VPS, install the database and create a dedicated user for the site, then take a snapshot of the server once the base setup is complete so you can roll back to it if needed.

Step 5: Transfer the Files and Database

Transferring Files with rsync

If you have SSH access to both servers, rsync is the best tool for the job, because on repeat runs it only transfers what has changed:

rsync -avz --progress user@old-server:/var/www/example.com/ /var/www/example.com/

You can run it once a day before the cutover, then one last quick pass at cutover time to copy only the new files.

Importing the Database

mysql -u root -p -e "CREATE DATABASE dbname CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
mysql -u dbuser -p dbname < db.sql

Then update the site's configuration file with the new connection details, and set file permissions so the web server can read the files and write only to the upload directories.

Step 6: Test the Site Before Changing DNS

This step is the difference between a safe migration and an improvised one. You can preview the site on the new server from your own computer only, by editing your hosts file, without affecting a single visitor.

  • On Windows: C:\Windows\System32\drivers\etc\hosts (open it as administrator).
  • On Linux and macOS: /etc/hosts.

Add a line like this:

203.0.113.10 example.com www.example.com

Then open the site and check:

  • The home page, inner pages and images.
  • Logging in and the admin dashboard.
  • Forms, the shopping cart and a test checkout, if you have one.
  • The error logs on the new server.

Don't forget to remove the line from your hosts file once testing is done.

Step 7: The Final Cutover

  1. Enable maintenance mode or freeze changes on the old site.
  2. Take a final database export and import it on the new server.
  3. Run rsync one last time.
  4. Change the DNS A records to the new server's address. If you need details on this step, see how to point a domain to your VPS.
  5. Issue an SSL certificate on the new server as soon as the domain resolves to it, for example with Let's Encrypt:
sudo certbot --nginx -d example.com -d www.example.com

Protecting Your Google Rankings

Keep Your URLs Exactly the Same

The most important SEO rule: don't change your URL structure during the migration. Same domain, same paths and same protocol means Google will only notice a change of IP address, which is perfectly normal and does not affect rankings.

If You Have to Change URLs

Use permanent 301 redirects from every old URL to its matching new URL, not to the home page. Here is an example in Nginx:

location = /old-page {
    return 301 /new-page;
}
ChangeExpected SEO impactWhat to do
Changing hosts onlyNegligible, as long as the site stays upTest thoroughly and switch DNS
Changing URL structurePossible temporary fluctuations301 redirects for every URL
Changing the domainLonger fluctuations301 redirects plus the Change of Address tool in Search Console
Moving to HTTPSNeutral or positive301 redirect from HTTP

Monitoring Google Search Console

After the cutover, keep an eye on the following in Search Console:

  • The indexing report, to spot any rise in 404 or 5xx errors.
  • Crawl stats, to make sure Google reaches the site without errors.
  • Resubmitting your sitemap.
  • Checking a few important pages with the URL Inspection tool.

Final Step: Don't Cancel the Old Hosting Right Away

Keep the old hosting running for at least a few days after the cutover. Some networks may hold on to the old address for a while, and you may discover a file or setting you forgot. Once you are sure all traffic and orders are reaching the new server, raise the TTL back to a higher value, then cancel the old hosting.

If you are looking for a new server to move your site to, check out our VPS plans and choose the location closest to your audience.

FAQ

Will changing hosts affect my Google rankings?

Changing hosts on its own usually doesn't affect rankings, as long as the domain, URLs and content stay the same and the site remains available without errors. Ranking drops typically come from long outages, 404 errors caused by missing files, changing URLs without 301 redirects, or a very slow new server.

How long does a DNS change take to propagate?

It depends mainly on the previous TTL. If you lowered it to a few minutes in advance and waited for the old value to expire, most visitors will reach the new server shortly after the switch, although a few may stay on the old address a little longer because of how some networks are configured.

What should I do about orders or comments that arrive during the migration?

The best approach is to enable maintenance mode or freeze new submissions on the old site right before the final export, then switch over quickly. If any data still lands on the old server after the cutover, keeping it running for a few days lets you retrieve that data and add it manually.

Do I need to move my email along with the website?

If your email is hosted on the same old server, then yes, you need to plan for it, or your mail will stop when the hosting is cancelled. Many people use the migration as a chance to move email to a standalone service, taking care not to change the MX records until the new service is ready.

Related guides