Redirect all domains to single domain with parameters

I have a website for a company who has lots of branches. Each of these branches has it’s own domain pointing to the main company domain. Unfortunately, it appears that google has spidered each site with parameters from other sites i.e.

www.branch1.com/branch2/branch2page

My htaccess is below. Do I need to redirect to the root domain somehow?

Options +FollowSymlinks
RewriteEngine on

#Catch specific reference to a klvc page 
RewriteRule ^klvc/([-a-zA-Z0-9]+)/([0-9]+)$ /klvc/klvc_store.php?klvc=$1&mantext_id=$2 [L]
RewriteRule ^klvc/([-a-zA-Z0-9]+)$ /klvc/klvc_store.php?klvc=$1 [L]

#Catch specific reference to a news article
RewriteRule ^klvc/([-a-zA-Z0-9]+)/news/article-([0-9]+)$ /klvc/klvc_news.php?klvc=$1&newsid=$2 [L]
RewriteRule ^klvc/([-a-zA-Z0-9]+)/news$ /klvc/klvc_news.php?klvc=$1 [L]
 
#Catch specific reference to a booking form
RewriteRule ^klvc/([-a-zA-Z0-9]+)/booking/([a-zA-Z0-9]+)$ /locator/book/?id=$2 [L]

#Catch specific reference to a contact form
RewriteRule ^klvc/([-a-zA-Z0-9]+)/contact/([a-zA-Z0-9]+)$ /locator/book/?id=$2 [L]

Do my rules need to be

RewriteRule ^klvc/([-a-zA-Z0-9]+)/([0-9]+)$ http://www.domain.com/klvc/klvc_store.php?klvc=$1&mantext_id=$2 [L]

If I do this, my rewriting doesn’t work. Any pointers?

Many thanks

petersen,

With mod_rewrite, order is important. WHERE did you put your second block of code? Obviously, you put it before all the others so it was able to “hijack” those URIs and prevent them from redirecting (because it had already performed a redirection).

Each of these branches has it’s own domain pointing to the main company domain.

Are they all on their own servers? How are they being redirected? Are their domains all subdomains of your domain? Are they all in your subdirectories [OR parked domains]? THIS IS IMPORTANT, too, as it can allow you to make the redirections based on the subdomain requested!

Other than that second block, it all appears to be non-conflicted (should work fine - but I’d move the non-static first and second RewriteRules behind the static text RewriteRules anyway). That block, however, appears to conflict with your first RewriteRule so you have to use just one - your call.

Edit:

I just realized that the intended question for the second block of code was whether it’s better to use an external redirection or not. The answer obviously depends upon whether you want your main domain (and redirection) to be seen by the visitors or not (which is also dependent upon whether the ORIGINAL redirections are from “parked” domains or remote hosts). In general, the answer is NO.

Regards,

DK

Thanks David,

The best example of this happening is is you search for ‘Lad and Turner Opticians’.

You will see www.kodaklens.com with the parameters, but lower down you’ll see www.regaloptical.co.uk/klvc/lad-turner-opticians/572. I’ve since hard coded the URLs in the pages to the root www.kodaklens.co.uk domain, but the redirects don’t seem to work so

www.regaloptical.co.uk/klvc/lad-turner-opticians/572 redirects to

http://www.kodaklens.co.uk/klvc/klvc_store.php?klvc=lad-turner-opticians&mantext_id=572

With regards to the domains, I need to clarify how they are setup but I believe that each domain is pointed to the main kodaklens.co.uk domain (the domains don’t have hosting of their own). In addition, they are not sub-domains.

Does that clarify things a little?

petersen,

Yes, if the “other” domains are “parked” on top of your domain, that’s GREAT (for dealing with using mod_rewrite). With the links in the other domains, you don’t even need to get the domain’s information for the query string from the {HTTP_HOST} variable, just use your klvc/([a-zA-Z-]+)/([0-9]+) => klvc/klvc_store.php?klvc=$1&mantext=$2 [L] but only AFTER you’ve taken the static strings out with earlier RewriteRules!

Regards,

DK