You can do it like this using mod_rewrite near the top of the root .htaccess
file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain-(\d{4})\.(example\.com) [NC]
RewriteRule ^data/process/([a-z0-9-]+\.xml)$ https://%2/%1/$1 [R=301,L]
Where %1
and %2
are backreferences to the preceding CondPattern and $1
is a backreference to the captured group in the RewriteRule
pattern.
HOWEVER, I've just noticed you've tagged the question wpengine
. The webhost "WP Engine" no longer supports .htaccess
config files. Reference: https://wpengine.com/support/htaccess-deprecation/ - UPDATE: Although it seems this tag has since been removed from the question.
UPDATE: If the target domain is different (a later change to the question) then this would need to be hardcoded in the substitution string, replacing the %2
backreference. For example:
RewriteCond %{HTTP_HOST} ^subdomain-(\d{4})\.old-domain\.com [NC]
RewriteRule ^data/process/([a-z0-9-]+\.xml)$ https://new-domain.com/%1/$1 [R=301,L]
The example in the question is passing just the .xml
filename to the target URL, it is not passing the preceding URL-path, which is what the rule above is doing.