Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Redirect based on Domain?

Status
Not open for further replies.

StuH

Programmer
Mar 25, 2001
53
0
0
AU
Hi,

I have a webspace which currently has two different domain names pointing at it - one being a mysite.com address and one being a mysite.com.au.

The webhost says both addresses can only point to the same folder under my existing single plan and I would need to host a second space and point each domain to its own space.

I want to do this with a single space:

If a visitor arrives at the site using the .com address, I want it to show the website that is at mysite.com. If they arrive using the .com.au address, I want them to automatically be redirected to the mysite.com.au/aus folder, or in other words, the aus folder in my webspace.

Can anyone give me the process for achieving this?

Thanks,

Stu.
 
This surely is not a question for the HTML/CSS forum but rather the forum of whichever server you use.
 
You could do this with PHP (or other server-side code), or (as a last resort if you don't have access to any server-side scripting) with JavaScript.

Personally, instead of:
mysite.com.au --> mysite.com.au/aus
I would use:
mysite.com.au --> mysite.com/au

It keeps all traffic on one domain, and using 'au' as the folder instead of 'aus' keeps within ISO standards for country identification.

Basically, at the start of every page you need a script that does something like:
Code:
  [COLOR=green]// pseudocode[/color]
  if (DOMAIN_NAME == 'mysite.com.au') then redirect('[URL unfurl="true"]http://mysite.com/au/')[/URL]

Here are the fora for various scripting languages:
[ul]
[li]forum434 - PHP[/li]
[li]forum695 - Java (Servlets & JSPs)[/li]
[li]forum333 - ASP[/li]
[li]forum232 - Coldfusion[/li]
[li]forum219 - Perl[/li]
[li]forum216 - Javascript[/li]
[/ul]

---
Marcus
better questions get better answers - faq581-3339
accessible web design - zioncore.com
 
As manarth pointed out, this can easily be done with a scripting language. Find out what language your host/hosting plan supports and with the forum links above you should be able to find a simple script to take care of it.


Hope This Helps!

ECAR
ECAR Technologies

"My work is a game, a very serious game." - M.C. Escher
 
Many thanks manarth and ECAR!

I have access to PHP, so I should be able to work it out from there. And yes, I will use the au convention.

Stu.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top