You basically just need to perform the redirects in the order you've stated: 1, 2 and 3.
Assuming newdomain.com
and olddomain.com
point to different servers then you can use mod_alias:
Redirect 302 /page1 https://www.newdomain.com/page1
Redirect 302 /page2 https://www.newdomain.com/page2
# Redirect everything else to the home page
RedirectMatch 302 ^ https://www.newdomain.com/
However, redirecting to the home page is rarely a good user experience (and Google likely treats it as a soft-404 anyway). You could simply redirect /<other-url>
to newdomain.com/<other-url>
and allow the new site to handle it as a meaningful 404 - generally a better experience for users.
Note that Redirect
is prefix-matching. Everything after the matched URL (eg. /page1
) is appended onto the end of the target URL. If the old and new URLs are the same then you only need a single Redirect
directive to redirect everything:
Redirect 302 / https://www.newdomain.com/
Note that these are obviously 302 (temporary) redirects. Change to a 301 (permanent) redirect only when you are sure it's working OK. 301s are cached hard by the browser, so you don't want incorrect redirects cached by the client.
If olddomain.com
and newdomain.com
are physically hosted on the same filesystem then you'll need to use mod_rewrite instead since you'll need to check the host header for the domain being accessed. For example:
RewriteEngine On
RewriteCond %{HTTP_HOST} olddomain\.com [NC]
RewriteRule ^page1$ https://www.newdomain.com/page1 [R=302,L]
Obviously, it would be far more efficient if olddomain.com
and newdomain.com
point to different places.