I'm trying to set up redirection rules in my .htaccess file to redirect URLs from one domain to another while preserving a specific folder structure within the URL. Specifically, I want to redirect requests from www.example1.org/foldername/ to www.example2.org/foldername/, ensuring that the /foldername/ folder is maintained in the redirected URL.
I've tried using the following rewrite rule:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example1\.org[NC]
RewriteRule ^example/(.*)$ https://www.example2.org/foldername/$1 [R=301,L]
However, when I test this rule, the redirection works but it seems to strip off the /example/ folder, resulting in redirected URLs like https://www.example2.org/wp-content/themes/stratusx-child/template/upload/202011191605847805585.png instead of https://www.example2.org/foldername/wp-content/themes/stratusx-child/template/upload/202011191605847805585.png.
How can I modify the rewrite rule to ensure that the /foldername/ folder is preserved in the redirected URL?
Any insights or alternative approaches would be greatly appreciated. Thanks!