WordPress when changing domain (robots.txt + .htaccess redirect)

Last update: 22 Квітня, 2023

Category: Redirect, WordPress

In order to trigger a 301-redirect when accessing the old domain, but except for the robots.txt file, you need to specify the following in the .htaccess file of the old domain:

<FilesMatch "robots.txt$">
RewriteEngine off
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://newdomain.com/$1 [R=301,L]


User-Agent: *
Host: newdomain.com

If you just want to make a redirect using .htaccess file:

RewriteEngine On
RewriteCond %{HTTP_HOST} OLDDOMAIN.com
RewriteRule (.*) https://NEWDOMAIN.com/$1 [R=301,L]