Q:

Htaccess 301 Redirect with Parameter

I'm stuck with an 301 redirect in htaccess. I'd like to redirect from
https://subdomain.example.com/SOME_STRING

to
https://www.example.com/folder/SOME_STRING

The string can be different on any request. Can someone help me out here?

A:

If these two hostnames point to the same place then you'll need to use mod_rewrite in order to check the hostname being requested.
Try the following at the top of your .htaccess file:
RewriteEngine On

RewriteCond %{HTTP_HOST} ^subdomain\.(example\.com) [NC]
RewriteRule ^ https://www.%1/folder%{REQUEST_URI} [R=301,L]

The %1 backreference matches the example.com in the preceding CondPattern - this simply saves repetition. The REQUEST_URI server variable contains the full URL-path from the request, including the slash prefix.
In fact, this is almost identical to another recent question that matches any subdomain:
how to redirect all subdomains to another with parameter after the trailing slash using htaccess?
To hardcode the hostname in the substitution string (as mentioned in comments) then you would do the following:
RewriteCond %{HTTP_HOST} ^subdomain\.example\.com [NC]
RewriteRule ^ https://www.example.com/folder%{REQUEST_URI} [R=301,L]

