To match all remaining pages and redirect to the home page of the new site you'll need to use the RedirectMatch
directive (also from mod_alias). For example:
RedirectMatch 301 .* https://newdomain.com/
The RedirectMatch
directive uses regex to match the request URL, whereas Redirect
uses simple prefix matching.
You can't use a Redirect
directive here, which is prefix matching, because whilst a redirect such as Redirect / https://newdomain.com/
will match all the remaining URLs, it will redirect to the same URL-path at newdomain.com
. eg. /whatever.htm
would redirect to https://newdomain.com/whatever.htm
(which presumably doesn't exist - although that might actually be a good thing - since mass redirects to the home page will be seen as a soft-404 anyway by Google and a real 404 can be more informative for users).
Just to add, this does assume that newdomain.com
is hosted on a different server, otherwise, you'll get a redirect loop.