There exists a client that has many branches round the United kingdom. A few of their branches get their own sites using their own domains. The customer includes a part built system where going to:

shows the About Us page for your particular branch. Things I require is a method to map specific domain names for their branchId (this really is all saved inside a DB right now) to ensure that

maps to

This works best for me. Unsure in case your domain names can make use of a single general ruleset (ie. grab the ID after which utilize it within the rewriterule), otherwise you will need to repeat the final 3 lines per URL

Options +FollowSymLinks 
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^(www.)?$
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /aboutus\.php\?id=4\ HTTP/
RewriteRule ^.*$ [R=301,L]

You might take the important part from the host title and pass it for your script:

RewriteEngine on
RewriteCond %{QUERY_STRING} !(^|&)branchName=
RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.com$
RewriteRule .* $0?branchName=%1 [L,QSA]