By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,448 Members | 877 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,448 IT Pros & Developers. It's quick & easy.

Problem rying to Redirct Domain

P: n/a
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>
Sep 4 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Wayne Wengert schrieb:
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>


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
Sep 4 '05 #2

P: n/a
Wayne Wengert wrote:
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("Location.Hostname: " + location.hostname);
alert("Location.Hostname: " , location.hostname);
Google "javascript concatenation"

Mick
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>

Sep 4 '05 #3

P: n/a
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" <in**@martinkurz.in-berlin.de> wrote in message
news:11***************@elch.in-berlin.de...
Wayne Wengert schrieb:
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>


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

Sep 5 '05 #4

P: n/a

"Mick White" <mw***********@rochester.rr.com> wrote in message
news:qh*******************@twister.nyroc.rr.com...
Wayne Wengert wrote:
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("Location.Hostname: " + location.hostname);
alert("Location.Hostname: " , location.hostname);
Google "javascript concatenation"

Mick
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>

Sep 5 '05 #5

P: n/a
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" <mw***********@rochester.rr.com> wrote in message
news:qh*******************@twister.nyroc.rr.com...
Wayne Wengert wrote:
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("Location.Hostname: " + location.hostname);
alert("Location.Hostname: " , location.hostname);
Google "javascript concatenation"

Mick
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>

Sep 5 '05 #6

P: n/a
Wayne Wengert wrote:
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?


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
Sep 6 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.