Redirect Old Domain to New Domain via .htaccess
When moving a site from one domain to another, maintaining your visitors and search engine rankings is essential. Properly redirecting pages from your old domain to the new domain ensures that users and search engines can locate your content without disruption.
This guide provides practical steps to achieve a seamless migration.
Why Proper Redirection Matters
Redirecting your old domain’s pages to the equivalent pages on the new domain is critical for:
- Retaining Visitors: Ensures users who access old links are directed to the right location on the new domain.
- Preserving SEO: Prevents search engines from treating the old and new domains as separate entities, protecting your rankings and link equity.
Setting Up Redirection on an Apache Server
If you are using Apache and have not changed your site structure during the migration, you can use the following .htaccess
configuration.
Redirection for an Unchanged Site Structure
- Locate the
.htaccess
file in the root directory of your old domain. - Add the following code to redirect all traffic to your new domain:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^olddomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.olddomain.com$
RewriteRule (.*)$ http://www.newdomain.com/$1 [R=301,L]
</IfModule>
What It Does
- Redirects all requests from
olddomain.com
andwww.olddomain.com
to the corresponding pages onnewdomain.com
. - The
R=301
ensures a permanent redirect, preserving SEO benefits.
Handling Site Structure Changes
If your new domain has a different site structure, you will need to create additional redirects. These redirects can be set up in the .htaccess
file of the new domain.
Redirecting a Single Page
To redirect an individual page from the old location to a new one on the same domain, use:
Redirect 301 /old/old http://www.domain.com/new
Example: Redirects www.domain.com/old/old
to www.domain.com/new
.
Advanced Redirects for Pattern-Based Rules
For more complex scenarios, such as redirecting pages based on URL patterns or rules, you may need to use regular expressions in your .htaccess
file. Since these rules require advanced knowledge, they are not covered here. Consider consulting an SEO professional to ensure accuracy and effectiveness.
Best Practices for Redirects
Always Use 301 Redirects
A 301 redirect signals to search engines that content has permanently moved, transferring rankings and link equity to the new URL.Test Your Redirects
After setting up your.htaccess
rules, test them to ensure users and search engines are properly redirected.Monitor Your New Domain
Use tools like Google Search Console to monitor your site’s performance after the migration and fix any crawling or indexing issues.
Further notes...
A well-planned domain migration preserves both user experience and SEO. Whether you're keeping the same site structure or making changes, proper .htaccess
configurations are vital for a smooth transition.
If you’re unsure about setting up advanced rules or handling complex migrations, reach out to our team for tailored advice.