I have two websites. Let's say siteA.com
and siteB.com
.
Now I want to add 301 redirect to siteB.com
.
Some of pages of siteB.com
need to be redirected to some specific pages on siteA.com
All other pages of siteB.com
neet to redirect to the home page of siteA.com
including siteB's home page.
My final requirement is no one can access siteB after adding the redirection.
These are two wordpress sites. How can acomplish this with htaccess file or a wordpress plugin?
Asked
Active
Viewed 199 times
0

ashanrupasinghe
- 103
- 3
-
Do `siteA.com` and `siteB.com` point to different vHosts/servers? – MrWhite Nov 20 '21 at 11:38
-
Yes. Different. – ashanrupasinghe Nov 20 '21 at 12:29
1 Answers
1
Since siteA.com
and siteB.com
point to different vHosts/servers then you can remove all the existing directives in siteB.com/.htaccess
and use the simpler mod_alias Redirect
and RedirectMatch
directives.
For example:
# siteB.com/.htaccess
# Specific redirects
Redirect 301 /foo https://siteA.com/another-foo
Redirect 301 /bar https://siteA.com/another-bar
Redirect 301 /baz https://siteA.com/another-baz
# Redirect everything else to homepage on siteA.com
RedirectMatch 301 ^ https://siteA.com/
Test first with 302 (temporary) redirects to avoid potential caching issues.
NB: Redirecting everything else to the homepage on the other site will likely be seen as a soft-404 by search engines and isn't particularly helpful for users. It is often preferable to serve a more descriptive 404 instead.
My final requirement is no one can access siteB after adding the redirection.
Since everything is redirected, siteB.com
is effectively inaccessible.
Reference:

MrWhite
- 12,647
- 4
- 29
- 41