I have moved pages in various sub directories to the root directory and want to set up a 301 redirect for each page and keep any query string that might be present. For example:
www.example.com/folder/page1.html
will redirect to:www.example.com/page1.html
and
www.example.com/folder2/page2.html
will redirect to:www.example.com/page2.html
If a query string is present, which we sometimes use, I would like that preserved. There are multiple pages which were in multiple subfolders that I need to redirect. All could potentially have query strings.
I've done simple redirects for landing pages where the landing page has a definitive query string and can hard code the query string since it will always be the same. That's not the case here.
I did find the following example that is close, but don't understand enough of it to know if it will work, and there happens to be ONE subfolder whose contents aren't being moved, so...
RewriteEngine On
RewriteRule ^subfolder/(.*)$ /$1 [R=301,QSA,L]
.htaccess
file?