301 Redirect Setup for Domain Migration
This guide walks you through setting up 301 redirects when moving your website to a new domain. You’ll learn how to map old URLs to new ones, implement the redirects on your server, and verify everything works—so you preserve search rankings and avoid broken links.
What You’ll Need
- Access to your old domain’s hosting control panel (cPanel, Plesk, or similar) or server configuration files (.htaccess, nginx.conf, etc.)
- Access to your new domain’s hosting and a list of the new URLs
- A text editor (like Notepad or VS Code) to create or edit redirect rules
- A list of your old URLs (you can export this from your CMS or use a crawl tool)
- Optional: a web analytics tool (like Google Analytics) to compare traffic after migration
Step-by-Step
- Inventory your old URLs. Export a list of all URLs on your old domain. Include the full path (e.g., /products/red-widget). If you have a small site, you can list them manually. For larger sites, use a crawler or your CMS’s export feature.
- Map old URLs to new URLs. Create a spreadsheet with two columns: Old URL (path only) and New URL (full new URL). If your site structure is changing, match each old URL to its most relevant new page. If a page has no equivalent, decide whether to redirect it to the closest category or the homepage.
- Choose your redirect method. The method depends on your server:
- Apache (shared hosting): Use an .htaccess file in your old domain’s root folder.
- Nginx: Edit the server block configuration file.
- IIS (Windows): Use web.config or the IIS Manager.
- CMS plugin: If you use WordPress, a plugin like Redirection can handle this without touching server files.
- Create the redirect rules. For each old URL, write a 301 redirect to the new URL. In .htaccess, the syntax is:
Redirect 301 /old-page https://www.newdomain.com/new-page
For Nginx, use:
rewrite ^/old-page$ https://www.newdomain.com/new-page permanent;
For IIS web.config, use a rule with statusCode=”301″.
- Add a catch-all redirect (optional but recommended). To handle any URL you might have missed, add a rule that redirects all traffic from the old domain to the new domain’s homepage. In .htaccess:
Redirect 301 / https://www.newdomain.com/
In Nginx:
rewrite ^(.*)$ https://www.newdomain.com$1 permanent;
This ensures no visitor gets a 404. However, use this only if you have mapped all important URLs—otherwise, you’ll lose the SEO value of those pages.
- Test the redirects. Open a browser and go to an old URL (e.g., olddomain.com/old-page). You should be taken to the new URL. Check that the address bar shows the new domain and that the page loads correctly. Repeat for several URLs, including the homepage and a deep page.
- Check for mixed content and hardcoded links. After migration, search your new site for any links still pointing to the old domain. Update them to the new URLs. Also, ensure your new site uses HTTPS consistently.
- Update your sitemap and submit to search engines. Create a new sitemap for your new domain and submit it in Google Search Console and Bing Webmaster Tools. Also, submit a change of address in Google Search Console (under Settings) to speed up the transition.
- Monitor traffic and crawl errors. After a few days, check your web analytics and search console for drops in traffic or 404 errors. If you see issues, adjust your redirect rules accordingly.
Common Mistakes
- Using 302 redirects instead of 301. A 302 tells search engines the move is temporary, so they keep the old URL in the index. Always use 301 for permanent moves.
- Redirecting everything to the homepage. This loses the SEO value of individual pages and frustrates users looking for specific content. Map each old URL to a relevant new URL whenever possible.
- Forgetting to update internal links. If your new site still links to old URLs, users will bounce through redirects, slowing down the site and diluting link equity.
- Not testing before going live. A typo in a redirect rule can cause a redirect loop or a 500 error. Test thoroughly before you announce the migration.
- Ignoring the www vs non-www version. Make sure you redirect both olddomain.com and www.olddomain.com to the same new URL. Also, be consistent with your new domain’s www preference.
Tips
- Use a spreadsheet to plan. This makes it easy to spot missing mappings and keep track of what you’ve done.
- Keep the old domain active. Don’t cancel your hosting for the old domain until you are sure all traffic has shifted (usually 3–6 months).
- Use relative paths in your mapping. When writing rules, use the path only (e.g., /old-page) instead of the full old URL, so you can test on a staging server if needed.
- Add redirects in batches. If you have hundreds of URLs, add them in groups and test after each batch to isolate errors.
- Set up 404 monitoring. Use Google Search Console to see which old URLs are still returning 404s, then fix them.
Troubleshooting
Redirect loop error. This happens when a redirect rule sends the user to a URL that also has a redirect. Check that your new domain does not have a rule that redirects back to the old domain. Also, ensure you are not redirecting the new domain to itself.
500 Internal Server Error. This usually indicates a syntax error in your .htaccess or nginx config. Double-check the syntax, especially quotes and slashes. If you can’t access the site, use your hosting file manager to temporarily rename the .htaccess file, then fix it.
Redirect not working. Verify that the rule is in the correct file and that the file is being read. For Apache, ensure .htaccess is enabled (AllowOverride All). For Nginx, reload the configuration with sudo nginx -s reload. Also, clear your browser cache—browsers sometimes cache redirects.
Some URLs redirect, others don’t. Check for conflicting rules. For example, a catch-all rule placed before specific rules will override them. Put specific rules first, then the catch-all.
Search engines still showing old URLs. This is normal—it can take weeks for search engines to recrawl. Ensure your redirects are 301 and that you’ve submitted a change of address. Use the URL Inspection tool in Google Search Console to request indexing for key new pages.
Frequently Asked Questions
Q: What is the difference between a 301 and a 302 redirect?
A: A 301 is a permanent redirect that passes most link equity to the new URL. A 302 is temporary and tells search engines to keep the old URL in the index. For domain migration, always use 301.
Q: Should I redirect the old domain’s homepage to the new homepage?
A: Yes, the homepage should redirect to the new homepage. If you have a catch-all rule, it will handle this automatically, but it’s best to have an explicit rule for the root as well.
Q: How long should I keep the old domain active?
A: Keep it active for at least 6 months. Search engines may still have old links pointing to it, and some users may have bookmarked old URLs. After that, you can renew it or let it expire, but keep the redirects in place as long as possible.
Q: Can I use a plugin to do this in WordPress?
A: Yes, plugins like Redirection or Yoast SEO Premium allow you to set up redirects without editing server files. They are especially useful for beginners. However, they only work if WordPress is installed on the old domain.
Q: What if I don’t have a mapping for an old URL?
A: Use a catch-all redirect to send any unmapped URLs to the new homepage. This prevents 404 errors, but it’s better to map as many as possible to preserve SEO.
Q: Will I lose my search rankings after a domain migration?
A: If done correctly with 301 redirects, you may see a temporary dip, but rankings usually recover. The key is to map all important URLs, update internal links, and submit a change of address in Google Search Console.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.