Redirect URLs Exactly When You Change Domain Name

When I moved this site from an old host name to the current one, I did not want every deep link to die. I needed Apache to change domain name in the address bar while keeping the path exactly the same—/some/old/post/ stays /some/old/post/ on the new host.

This is the .htaccess pattern I used from asique.me to asique.net. Swap the hostnames for your own migration.

Change domain name with exact Apache URL redirects

Why Redirect Paths When You Change Domain Name

A bare homepage redirect is not enough. Bookmarks, search results, and shared links still hit the old host with full paths. Matching HTTP_HOST and rewriting ^(.*)$ to the new domain preserves those URLs.

Related Apache notes here: redirecting HTTP to HTTPS, password protect a folder with .htaccess, and macOS localhost permissions for Apache when testing locally.

Before and after change domain name URL redirects

Apache Rule to Change Domain Name and Keep Paths

Put this in the old domain’s root .htaccess (the vhost that still answers for the previous hostname):

RewriteEngine On
RewriteCond %{HTTP_HOST} ^asique.me$ [OR]
RewriteCond %{HTTP_HOST} ^www.asique.me$
RewriteRule ^(.*)$ https://asique.net/$1 [R=301,L]

Both apex and www on the old host are caught. The $1 backreference copies the path and query onto the new domain so you redirect URLs exactly—only the domain name changes.

Steps to change domain name with Apache exact URL redirects

Redirect Type: 301 vs 307

I use flags like this depending on how permanent the move is:

  • 301 Permanent Redirect — [R=301,L] when the domain change is final (search engines transfer signals over time)
  • 307 Temporary Redirect — [R=307,L] while testing or if the old domain might come back

For my asique.me → asique.net move I kept R=301 once HTTPS on the new host was solid.

Checklist After You Change Domain Name

  • DNS for the old host still points somewhere Apache can serve this .htaccess
  • New site loads on HTTPS before you flip the 301
  • CMS site URL / home URL already use the new domain (avoids redirect loops)
  • Test a deep path: http://old-domain.example/some/path/ should become https://new-domain.example/some/path/
  • Update Search Console / analytics properties for the new host when the move is permanent

One more practical note from my move: keep the old domain’s DNS alive long enough for the 301s to matter. If the old hostname stops resolving, nobody ever hits this rule—and you cannot change domain name redirects for traffic that never arrives.

I left the old DNS on a cheap parking plan for a few months, confirmed Search Console coverage on the new host, then retired the old name when the digests looked quiet.

FAQ: Change Domain Name Redirects

Do I need this on the new domain too?

No. This rule belongs on the old hostname’s document root (or the server block that still receives those requests).

Will query strings survive?

With this common Apache setup, query strings are usually passed through. If a host strips them, append the QSA flag.

What about Nginx?

Use a server-level return 301 https://new-domain$request_uri; instead of .htaccess.

Is a WordPress plugin required?

Not for host-level domain mapping. Plugins help inside one WordPress install; this rule fixes the old domain at Apache.

Conclusion

Need to change domain name without breaking deep links? Match the old HTTP_HOST values, rewrite to the new HTTPS host with $1, and use R=301 when the move is final. Paths stay exact—only the domain changes.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top