views:

64

answers:

2

We have a client who has many branches around the UK. Some of their branches have their own sites with their own domain names. The client has a part built system where visiting:

www.client.com/aboutus.php?id=branchId

shows the About Us page for that particular branch. What I need is a way to map specific domains to their branchId (this is all stored in a DB at the moment) so that

www.client.com/aboutus.php?id=4

maps to

www.branchid4.com/aboutus.php
A: 

You could take the crucial part out of the host name and pass it to your script:

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

This works for me. Not sure if your domains can work with a single general ruleset (ie. grab the ID and then use it in the rewriterule), otherwise you'll need to repeat the last 3 lines per URL

Options +FollowSymLinks 
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^(www.)?client.com$
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /aboutus\.php\?id=4\ HTTP/
RewriteRule ^.*$ http://www.branchid4.com/about.php? [R=301,L]
Sarah
Thanks Sarah. Not sure if that's going to be maintainable as we could have 8 pages per site and over 100 branches. I'm also wondering if I actually stated the redirect properly. I want the user to enter: www.branchid4.com/about usbut the page to actually be www.client.com/aboutus.php?id=4Does that make sense?
Jeepstone