2
RewriteCond %{HTTP_HOST} ^site.olddomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.site.olddomain\.com$
RewriteRule ^(.*)$ https://site.newdomain.com/$1 [R=301,L]

All posts URLs are redirecting successfully. But the problem is my old multisite site_id is different from the new multisite site_id.

So all site.olddomain.com/wp-content/uploads/sites/7/.. is redirecting to site.newdomain.com/wp-content/uploads/7/...

But the site_id at the new domain is 2, not 7.

I tried this

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

But still it is redirecting wrongly.

0
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.