301 redirect with args in .htaccess
If you ever need to redirect one domain name to another (using apache) and you need to do it in code you can simply create a .htacess file in the root of the folder that needs to be redirected and pop the standard 301 redirect in there. That doesn’t really help though if you want all the subdirectories of your old domain name to map to the new one, in which case pop the following in:
RewriteEngine OnRewriteRule ^.*$ http://example.com/$0 [R=301,L]
Swap example.com for your destination; any request below the folder with this .htaccess is redirected, preserving subpath and query string.
If you’re on nginx rather than Apache the equivalent one-liner inside a server block is:
return 301 https://example.com$request_uri;
And if you’re fronting the site with Cloudflare (no origin involved), a zone-level Redirect Rule in the CF dashboard handles host-or-path redirects without touching server config at all — usually the least-friction option in 2026.