Search code examples
wordpress.htaccesshttp-redirectprestashophttp-status-code-301

Redirect all subfolders from domain A to same subfolder in domain B


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?


Solution

  • I understand the question such that you actually want to redirect all content from one to another domain. That could be done like that:

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^(www\.)?domainA\.com$
    RewriteRule ^ https://domainB.com%{REQUEST_URI} [QSA,R=301,END]
    

    It makes sense to start out with a R=302 temporary redirection and only change that to a R=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:

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^(www\.)?domainA\.com$
    RewriteRule ^/?[^/]+/ https://domainB.com%{REQUEST_URI} [QSA,R=301,END]
    

    Obviously the same hints as above apply...