/ Sysadmin

htaccess redirect old pages to new domain

Sometimes you need to change a domain name, and you want to redirect all old pages to the new domain name.

On your existing domain, you can redirect all requests to the new domain with something like the following:

In your .htaccess file:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

# Redirect all traffic and pages to new domain
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
</IfModule>

The [L] flag causes mod_rewrite to stop processing the rule set. In most contexts, this means that if the rule matches, no further rules will be processed. See https://httpd.apache.org/docs/2.4/rewrite/flags.html#flag_l