Connecting Tech Pros Worldwide Forums | Help | Site Map

Problem rying to Redirct Domain

Wayne Wengert
Guest
 
Posts: n/a
#1: Sep 4 '05
I have a web site to which multiple domains point and I want to redirect to
a specific subdirectory for specific domain references. I found the
following script and am trying to use it but I cannot get it to work. I
added the alert statements to try to see what is happening but they both
retund a value of 0? Any ideas as to how I can accomplish this?

Wayne

==============================
<script language="JavaScript">
<!--
alert("Location.Hostname: " & location.hostname);
alert("urlloc: " & location.href);
if ( location.hostname == "AltDomain.org" ) {
window.location = "/AltDomainsubDirectory/";
} else if ( location.hostname == "domain_two.com" ) {
window.location = "/users/domain_two/";
} else {
// build current content
}
-->
</script>



Martin Kurz
Guest
 
Posts: n/a
#2: Sep 4 '05

re: Problem rying to Redirct Domain


Wayne Wengert schrieb:[color=blue]
> I have a web site to which multiple domains point and I want to redirect to
> a specific subdirectory for specific domain references. I found the
> following script and am trying to use it but I cannot get it to work. I
> added the alert statements to try to see what is happening but they both
> retund a value of 0? Any ideas as to how I can accomplish this?
>
> Wayne
>
> ==============================
> <script language="JavaScript">
> <!--
> alert("Location.Hostname: " & location.hostname);
> alert("urlloc: " & location.href);
> if ( location.hostname == "AltDomain.org" ) {
> window.location = "/AltDomainsubDirectory/";
> } else if ( location.hostname == "domain_two.com" ) {
> window.location = "/users/domain_two/";
> } else {
> // build current content
> }
> -->
> </script>[/color]

First of all: location is an object, you have to set the path to the property href:

window.location.href = "/AltDomainsubDirectory/";

You should get the actual hostname bei window.location.hostname
Mick White
Guest
 
Posts: n/a
#3: Sep 4 '05

re: Problem rying to Redirct Domain


Wayne Wengert wrote:[color=blue]
> I have a web site to which multiple domains point and I want to redirect to
> a specific subdirectory for specific domain references. I found the
> following script and am trying to use it but I cannot get it to work. I
> added the alert statements to try to see what is happening but they both
> retund a value of 0? Any ideas as to how I can accomplish this?
>
> Wayne
>
> ==============================
> <script language="JavaScript">
> <!--
> alert("Location.Hostname: " & location.hostname);[/color]


alert("Location.Hostname: " + location.hostname);
alert("Location.Hostname: " , location.hostname);
Google "javascript concatenation"

Mick
[color=blue]
> alert("urlloc: " & location.href);
> if ( location.hostname == "AltDomain.org" ) {
> window.location = "/AltDomainsubDirectory/";
> } else if ( location.hostname == "domain_two.com" ) {
> window.location = "/users/domain_two/";
> } else {
> // build current content
> }
> -->
> </script>
>
>[/color]
Wayne Wengert
Guest
 
Posts: n/a
#4: Sep 6 '05

re: Problem rying to Redirct Domain


Martin;

Thanks for the response. I think I am setting the target directory as you
indicated? After correcting my alert statements it turns out that the domain
retuned by location.hostname and location.href are both the same value - the
url of the site, not the url that the user typed in?

Also, if I change "location.hostname" to "window.location.hostname" it does
not seem to change anything?

Wayne

"Martin Kurz" <info@martinkurz.in-berlin.de> wrote in message
news:1125832747.935633@elch.in-berlin.de...[color=blue]
> Wayne Wengert schrieb:[color=green]
>> I have a web site to which multiple domains point and I want to redirect
>> to
>> a specific subdirectory for specific domain references. I found the
>> following script and am trying to use it but I cannot get it to work. I
>> added the alert statements to try to see what is happening but they both
>> retund a value of 0? Any ideas as to how I can accomplish this?
>>
>> Wayne
>>
>> ==============================
>> <script language="JavaScript">
>> <!--
>> alert("Location.Hostname: " & location.hostname);
>> alert("urlloc: " & location.href);
>> if ( location.hostname == "AltDomain.org" ) {
>> window.location = "/AltDomainsubDirectory/";
>> } else if ( location.hostname == "domain_two.com" ) {
>> window.location = "/users/domain_two/";
>> } else {
>> // build current content
>> }
>> -->
>> </script>[/color]
>
> First of all: location is an object, you have to set the path to the
> property href:
>
> window.location.href = "/AltDomainsubDirectory/";
>
> You should get the actual hostname bei window.location.hostname[/color]


Wayne Wengert
Guest
 
Posts: n/a
#5: Sep 6 '05

re: Problem rying to Redirct Domain



"Mick White" <mwhite13BOGUS@rochester.rr.com> wrote in message
news:qhCSe.76937$Hx4.62785@twister.nyroc.rr.com...[color=blue]
> Wayne Wengert wrote:[color=green]
>> I have a web site to which multiple domains point and I want to redirect
>> to a specific subdirectory for specific domain references. I found the
>> following script and am trying to use it but I cannot get it to work. I
>> added the alert statements to try to see what is happening but they both
>> retund a value of 0? Any ideas as to how I can accomplish this?
>>
>> Wayne
>>
>> ==============================
>> <script language="JavaScript">
>> <!--
>> alert("Location.Hostname: " & location.hostname);[/color]
>
>
> alert("Location.Hostname: " + location.hostname);
> alert("Location.Hostname: " , location.hostname);
> Google "javascript concatenation"
>
> Mick
>[color=green]
>> alert("urlloc: " & location.href);
>> if ( location.hostname == "AltDomain.org" ) {
>> window.location = "/AltDomainsubDirectory/";
>> } else if ( location.hostname == "domain_two.com" ) {
>> window.location = "/users/domain_two/";
>> } else {
>> // build current content
>> }
>> -->
>> </script>[/color][/color]


Wayne Wengert
Guest
 
Posts: n/a
#6: Sep 6 '05

re: Problem rying to Redirct Domain


Thanks Mick. I always forget those difference between languages. Changing
the "&" to "+" got the alert statements working but I still am not getting
the url the user is entering?

Wayne

"Mick White" <mwhite13BOGUS@rochester.rr.com> wrote in message
news:qhCSe.76937$Hx4.62785@twister.nyroc.rr.com...[color=blue]
> Wayne Wengert wrote:[color=green]
>> I have a web site to which multiple domains point and I want to redirect
>> to a specific subdirectory for specific domain references. I found the
>> following script and am trying to use it but I cannot get it to work. I
>> added the alert statements to try to see what is happening but they both
>> retund a value of 0? Any ideas as to how I can accomplish this?
>>
>> Wayne
>>
>> ==============================
>> <script language="JavaScript">
>> <!--
>> alert("Location.Hostname: " & location.hostname);[/color]
>
>
> alert("Location.Hostname: " + location.hostname);
> alert("Location.Hostname: " , location.hostname);
> Google "javascript concatenation"
>
> Mick
>[color=green]
>> alert("urlloc: " & location.href);
>> if ( location.hostname == "AltDomain.org" ) {
>> window.location = "/AltDomainsubDirectory/";
>> } else if ( location.hostname == "domain_two.com" ) {
>> window.location = "/users/domain_two/";
>> } else {
>> // build current content
>> }
>> -->
>> </script>[/color][/color]


RobG
Guest
 
Posts: n/a
#7: Sep 6 '05

re: Problem rying to Redirct Domain


Wayne Wengert wrote:[color=blue]
> Thanks Mick. I always forget those difference between languages. Changing
> the "&" to "+" got the alert statements working but I still am not getting
> the url the user is entering?[/color]

Please don't top-post.

What do you mean by 'the URL the user is entering'?

The Location object is accessed through the window object. To see the href:

alert( window.location.href );

or more simply

alert( location.href );

Note the lower case 'l' for 'location'.

<URL:http://docs.sun.com/source/816-6408-10/location.htm#1193494>

The href of the current window is normally displayed in the browser's
address field but you have no access to that using script (unless you
know of a browser that specifically gives you access to it).

The href of the window is whatever it is, the user can type whatever
they want into the address field, it will not modify the Location object
until the user asks the browser to load the new URL. When that happens,
your script is unloaded and you can't access the new Location.

[...]

--
Rob
Closed Thread