How to redirect visitors to a subpage depending on the url they entered

My client has just purchased hosting (not through my hosting company but one they wanted to use) for their main domain but they also have a number of more specific domains that need to be pointed to a specific page in the website. The trouble is that for these additional the new host say they can only point to the main domain (IP address) at DNS level and not to a specific page.

Any idea how to go about this (apart from using another host!)? Can I use a script that can tell what url they have typed into their browser and forward them to the correct page? I want to avoid the need for a hosting package for each domain just for a simple redirect page!

Hope this all makes sense…



Update: This host seems to think it can be done by a http header lookup on the index page - this php or javascript looks at where a visitor came from e.g. and directs them to However, they don’t supply or support such a script (great, eh?).

I did a google search for it but didn’t find the goods.

Any suggestions?


I’m considering you’re using apache…
mod_rewrite can definitely solve that. You do not need to write php code for that.
Just add the following to the .htaccess in the root of the web server:

 RewriteEngine on
 RewriteCond %{HTTP_HOST} ^
 RewriteRule (.*) [R=301,L]

Thanks for your help - the host has informed me though that it is a Zeus webserver - I tested it and it won’t work. Is there a workaround or maybe a php version that will do the same?

I did find that Zeus offers something similar to htaccess but can’t make any sense of it:

While we do support .htaccess files, much of the mod_rewrite functionality is not available.

However, you can use Zeus rewrite rules which work in a very similar way. For example, a mod_rewrite rule of:

RewriteCond %{REQUEST_FILENAME}!-f
RewriteRule [1]*\.html$ index.php

Would convert to:

match URL into $ with [2]*\.html$
if matched then
set URL = index.php

This should be placed in a file named rewrite.script in your web directory.

Thanks for your help!


  1. ^/ ↩︎

  2. ^\/ ↩︎

My good friend Alan Jewitt at web by numbers cracked this one for me using a simple yet effective php script:

$server = $_SERVER["SERVER_NAME"];
$server = str_replace("www.","",$server);
If ($server == "")
elseIf ($server == "")


And it works beautifully.

Thanks again, Alan!

As I understand you need a special software that actually tells the internet infrastructure where to find the second domain. I had a similar problem with my Canal Boat Holidays UK website and you need Internet Internal Server or something like that…

I had a similar problem with my Canal Holidays UK website that had random errors on access and there was a glitch that needed to be fixed but I ain’t a programmer so I had to bare the errors until someone enlightened me.