I have 2 domains, and need to redirect all subfolders from domain A to the same subfolder in domain B.
Domain A = WordPress
Domain B = Prestashop 1.7
Example of what I need to accomplish:
https://domainA.com/subfolder1
-> 301 -> https://domainB.com/subfolder1
There’s a lot of subfolders in domain A, so I need my rule to be general
Can you point me in the right direction?
3
Answers
You have to edit htaccess file of wordpress domain website.
Add htaccesss code like below.
It will be redirect https://domainA.com/subfolder1 to https://domainB.com/subfolder1
You must have to try. I hope this can be helpful. thanks
I understand the question such that you actually want to redirect all content from one to another domain. That could be done like that:
It makes sense to start out with a
R=302
temporary redirection and only change that to aR=301
permanent redirection once you have sorted out everything to your satisfaction. That prevents caching issues.Such rule can be implemented in a distributed configuration file (".htaccess") if their consideration is enabled for the host "domainA.com". You should prefer to use the real http server’s host configuration instead though, if you have access to that.
UPDATE:
In your comment you confirm that you indeed only want to redirect "subfolders", not all resources. I understand "subfolders" as URLs with a path component that has a "subfolder" followed by a "/" and some other resource after that. Though that does not have to correspond to actual folders in the server side file system at all…
In that case this variant should work:
Obviously the same hints as above apply…
Just an alternative solution….
In that case, you don’t need the additional condition that checks the requested hostname. (Unless you are hosting other domains on this account?)
In order to detect whether the requested URL-path contains an initial subfolder you could just check to see whether the URL-path contains a slash (
/
), rather than explicitly matching the first path segment, since this isn’t used in the substitution string.For example:
In
.htaccess
(directory context) the URL-path that is matched by theRewriteRule
pattern does not start with a slash, so if a slash occurs anywhere in the URL-path we can assume that there must be a "subfolder". Or, there is path-info, but since this is a WordPress site (and I assume you are using "pretty permalinks", otherwise the existing answer won’t work either) then you don’t have path-info on any legitimate URLs.This redirect needs to go near the top of the
.htaccess
file, before the# BEGIN WordPress
section.