How to retain SEO when switching domains or URL structure

If you ever move your website to a new domain and you are also chaning the URL structure of you web site it is not enough just to place a domain redirect form the old domain! You will have to update the .htaccess file at your new domain’s web root directory to avoid 404 errors which will affect both your reputation with visitors and ranking in search engines.

# Redirect to main domain.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} sub-domain.domain.example [NC]
RewriteRule ^(\d+)/(\d+)/(.*)$ https://domain.example/$3 [L,R=301]
RewriteRule ^tag/(.*)$ https://domain.example/tag/$1 [L,R=301]
RewriteRule ^category/(.*)$ https://domain.example/category/$1 [L,R=301]
RewriteRule ^page/(.*)$ https://domain.example/page/$1 [L,R=301]
RewriteRule ^(.*)$ https://domain.example/$1 [L,R=301]

If you are switching domains and changing the URL structure place the above logic in an .htaccess file in the web root directory of the your domain, e.g public_html.

I recently combined blogs, accessed through different sub-domains, served by a single WordPress MU setup, e.g. the and blog sites into Because the above domains did not really exist, WordPress MU utilizes a wildcard DNS record to capture requests to sub-domains, I had to create a real web environment on the server for each sub-domain I wanted to redirect. In the public_html directory for each of those sub-domains I had to create an .htaccess file with a 301 redirect to the new domain based on the URL structure and purpose.

Theoretically, I could have kept the wildcard DNS record and just used a single .htaccess file at the top-level domain with the same logic, but for each sub-domain, redirecting traffic from the sub-domains to the top-level domain and then redirecting, again, to the new URL structure. Wildcards can be an issue, especially when planning to use sub-domains for other things, which is why I did not go this route.

Discover more from Titan Fusion

Subscribe now to keep reading and get access to the full archive.

Continue reading