Introduction
Migrating a website to a new URL structure requires careful planning to ensure all old URLs are redirected properly to the new URLs. This process involves recording the current URL structure, matching old URLs to new URLs, and creating redirects in the .htaccess file. This guide will walk you through the steps to accomplish this task.
Analyzing and Recording the Current URL Structure
- Crawl the Existing Website:
- Use a tool like Screaming Frog to crawl the website and extract the URL structure.
- Save the results in a CSV or Excel file for easy reference.
- Generate a Sitemap:
- Ensure you have the latest XML sitemap of the website.
- Use the sitemap to cross-verify the URLs captured by Screaming Frog.
- Backup the Data:
- Preserve a copy of the crawl results and sitemap for future reference.
Preparing for the New URL Structure
- List the New URLs:
- Obtain the new URL structure from the development team.
- Ensure all new URLs are finalized before starting the mapping process.
- Categorize Content:
- Separate blog URLs from other URLs, as blog URLs might require different handling.
Matching Old URLs to New URLs
- Mapping Old to New URLs:
- For each old URL, find the corresponding new URL.
- Document the matches in a spreadsheet, ensuring every old URL has a corresponding new URL.
- Note that new URLs do not necessarily need to have a matching old URL.
- Handling Blog URLs:
- Create a separate list of old blog URLs.
- Note these URLs need special handling, typically via a support ticket for content migration.
Tips for Matching URLs:
- 1 to 1 Matching:
- Direct match where an old URL has a new URL counterpart.
- Example:
/about
->/about-us/
- Many to 1 Matching:
- Multiple old URLs redirect to a single new URL.
- Example:
/services/3d-printing
,/services/digital-scanner
->/services/advanced-dental-technology.html
Creating the .htaccess File for Redirects
- Basic .htaccess Setup:
- Start with enabling the rewrite engine:apacheCopy code
RewriteEngine On
- Start with enabling the rewrite engine:apacheCopy code
- Redirect Non-www to www (Same Domain):
- Ensure all non-www traffic is redirected to the www version:apacheCopy code
RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
- Ensure all non-www traffic is redirected to the www version:apacheCopy code
- Redirect Old Domain to New Domain:
- Redirect all traffic from the old domain to the new domain:apacheCopy code
RewriteCond %{HTTP_HOST} ^old-domain\.com$ [NC] RewriteRule ^(.*)$ https://new-domain.com/$1 [R=301,L]
- Redirect all traffic from the old domain to the new domain:apacheCopy code
- Custom Error Pages:
- Set up custom error pages:apacheCopy code
ErrorDocument 404 /custom_404.html
- Set up custom error pages:apacheCopy code
- Redirecting Index Page:
- Redirect
index.html
to the root:apacheCopy codeRewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/ RewriteRule ^index\.html$ / [R=301,L]
- Redirect
- Specific Redirects for Old to New URLs:
- Add the specific redirects:apacheCopy code
# Example of 1 to 1 Redirect Redirect 301 /about https://www.newdomain.com/about-us/ # Example of Many to 1 Redirect Redirect 301 /services/3d-printing https://www.newdomain.com/advanced-dental-technology.html Redirect 301 /services/digital-scanner https://www.newdomain.com/advanced-dental-technology.html
- Add the specific redirects:apacheCopy code
- Prevent Access to Sensitive Files:
- Add security measures to prevent access to sensitive files:apacheCopy code
<FilesMatch "\.(htaccess|htpasswd|ini|phps|fla|psd|log|sh)$"> Order Allow,Deny Deny from all </FilesMatch>
- Add security measures to prevent access to sensitive files:apacheCopy code
Examples of URL Matching:
1 to 1 Matching:
- Old URL:
/about
- New URL:
/about-us/
apacheCopy codeRedirect 301 /about https://www.newdomain.com/about-us/
Many to 1 Matching:
- Old URLs:
/services/3d-printing
,/services/digital-scanner
- New URL:
/services/advanced-dental-technology.html
apacheCopy codeRedirect 301 /services/3d-printing https://www.newdomain.com/advanced-dental-technology.html Redirect 301 /services/digital-scanner https://www.newdomain.com/advanced-dental-technology.html
Step 5: Testing and Finalizing
- Test the Redirects:
- Use tools like
curl
or online HTTP status checkers to ensure all redirects are working as expected. - Verify that no URLs are missed and all redirects point to the correct new URLs.
- Use tools like
- Incremental Testing:
- Implement and test changes incrementally to catch errors early.
- Backup and Version Control:
- Keep backups of the original .htaccess file.
- Use version control to track changes.
Tools for Crawling and URL Mapping
- Screaming Frog SEO Spider:
- This tool can crawl websites and extract URLs, helping you create a complete list of old URLs.
- It also provides options to compare crawls, which can be useful for mapping old URLs to new URLs.
- URL Profiler:
- This tool can help extract various URL data, such as meta information and social metrics, which can aid in the URL mapping process.
- It integrates with Screaming Frog and other SEO tools for comprehensive analysis.
Tools for Creating .htaccess Redirects
- htaccess Redirect Generator:
- Websites like htaccessredirect.net provide simple interfaces to generate .htaccess redirect rules.
- You can input your old and new URLs, and the tool will generate the necessary .htaccess code.
- Online Regex Tools:
Tools for Testing Redirects
- Redirect Checker:
- Tools like Redirect-Checker.org allow you to test your redirects to ensure they are working correctly.
- You can enter your old URL and see if it correctly redirects to the new URL.
- HTTP Status Code Checker:
- Websites like httpstatus.io let you check the HTTP status codes for multiple URLs, ensuring your redirects return the expected 301 status.
Example Workflow Using These Tools
- Crawl the Existing Site:
- Use Screaming Frog to crawl the existing website and export the list of old URLs.
- Generate New URL List:
- Obtain the list of new URLs from your development team or sitemap.
- Map Old URLs to New URLs:
- Use a spreadsheet to manually match old URLs to new URLs, or use URL Profiler for more automated analysis.
- Create Redirects:
- Use the htaccess Redirect Generator to create the necessary .htaccess rules based on your URL mappings.
- Test Redirects:
- Use Redirect Checker and HTTP Status Code Checker to verify that your redirects are correctly implemented and return the expected status codes.
- Implement and Validate:
- Implement the .htaccess file on your server and validate each redirect using tools and manual checks.
By leveraging these tools, you can streamline the process of matching old URLs to new URLs and generating the necessary .htaccess redirects. This approach helps ensure accuracy and efficiency in your URL migration projects.