WordPress multisite htaccess redirection to new domain

RewriteCond %{HTTP_HOST} ^site.olddomain.com/wp-content/uploads/sites/2$

The HTTP_HOST server variable contains just the hostname (the value of the Host HTTP request header). It does not contain the URL-path, so the above condition is never going to match.

But the site_id in new domain is 2.

But your directive appears to be trying to do the opposite… checking for 2 on the site.olddomain.com and redirecting to 7 on the new domain? (But what about your other sites?)

RewriteRule ^(.*)$ https://site.newdomain.com/wpcontent/uploads/sites/7/$1 [R=301,L]

You also appear to have omitted the hyphen (-) in wpcontent?

You need to write this specific redirect something like the following intsead:

RewriteCond %{HTTP_HOST} ^site\.olddomain\.com [NC]
RewriteRule ^(wp-content/uploads/sites)/2/(.*) https://site.newdomain.com/$1/7/$2 [R=301,L]

Some notes:

  • Don’t forget to escape the dots in the pattern to match literal dots (you’ve escaped some and not others).
  • I’ve omitted the trailing $ on the CondPattern that checks against HTTP_HOST in order to catch FQDN (that end in a dot).
  • I’ve added the NC flag to the RewriteCond directive to make the check case-insensitive. This is really just to catch malformed requests (all browsers will lowercase the hostname in the request).
RewriteCond %{HTTP_HOST} ^site.olddomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.site.olddomain\.com$

These two RewriteCond directives can be combined into one, by simply making the www. part optional:

RewriteCond %{HTTP_HOST} ^(www\.)?site\.olddomain\.com