I am a php newbie and am trying to write a script that will direct visitors to specific pages on my website based on which of several url’s they have entered (all are aliases of the main website).
While all visitor will be directed to the same website, I want visitors to start at specific pages based on their interests, rather than having to drill down from various menus.

For example, let us call the main domain abc.com.

I have the following domains which are being used as aliases:

abcfurniture.com
abcbooks.com
abcgifts.com
abcfood.com
abcstationery.com

So if a visitor enters abcfurniture.com, I want them to go to:

abc.com/furniture.html

etc. etc.

I know that I can use Header and location to direct them to a specific page. The question is how do I capture exactly which url they have entered.

I was thinking perhaps of $_SERVER[HTTP-HOST] to capture the url entered. Then I could use if ... then statements, or case, or switch with

header('Location: http://www.abc.com/furniture.html'); 

Any suggestions as the best way of doing this?

Incidentally, in researching this question, I have found numerous related questions involving visitors from old
pages, etc., but very little on using one domain with a number of aliases.

Your help is greatly appreciated.

    If you have mod_rewrite available, you might be able to do something like this:

    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} .*\.?abcfurniture.com
    RewriteRule .* http://abc.com/furniture.html [L]
    
    RewriteCond %{HTTP_HOST} .*\.?abcbooks.com
    RewriteRule .* http://abc.com/books.html [L]
    
    # etc. for all hosts
    # Alternatively, if it's always in the form of abc(page).com,
    # you can get rid of all of the Cond's above and just use:
    
    RewriteCond %{HTTP_HOST} .*\.?abc(.+)\.com
    RewriteRule .* http://abc.com/%1.html
      $_SERVER['SERVER_NAME'];

      then like you said use some if statements, then redirect using header();

        Please don't cross-post the same post across different forums. Thanks.

          Sorry about cross- posting. Wasn't sure newbies was the best place to start.

          Thank you for your suggestion for RewriteEngine. I'll have to check with my service provider.

          Incidentally, will $_SERVER[HTTP_HOST] and/or [SERVER_NAME] give me the exact url entered, e.g. abcfurniture.com ?

          Thanks again.

            HTTP_HOST is sent by the client and therefore may not always be present.

            SERVER_NAME is derived from the Virtual Host name on the server itself, so I would tend to trust this more.

            For more information on these different indeces, see: [man]variables.predefined[/man].

              Write a Reply...