Javascript Q: read subdomainprefix from url

M

M@r(o

Hello,

Could someone please help me out on this problem please :)?

All subdomains are redirected tot our main domain www.lelystad.nl and
with javascript redirected to a specific page, eg (Partial):
if (window.location.href == 'http://touristinfo.lelystad.nl' ||
window.location.href == 'http://touristinfo.lelystad.nl/' ||
window.location.href == 'http://www.touristinfo.lelystad.nl' ||
window.location.href == 'http://www.touristinfo.lelystad.nl/') {

window.location.replace("http://www.lelystad.nl/smartsite.shtml?id=50980");

}
This works like a charm for all the stated subdomains in this script.
But whenever someone choose to typ another subdomain which is not
stated in the script I would like to use the subdomainprefix in an URL
to feed the searchengine:

http://www.lelystad.nl/smartsite.shtml?id=search&SArea=alm&SThema=0&zoekterm=SUBDOMAIN

TIA
Grtz,
Marco.
 
S

shimmyshack

do these subdomains exist in reality?

Try http://bannas.google.com/ you wont get very far, because there is
no mapping between the host and the IP for that host.

In short, subdomains have to be real and public for your server to
receive the request. If they are real, using apache rewrites is better
as you say - some people dont have js on.
 
E

Evertjan.

M@r(o wrote on 31 okt 2006 in comp.lang.javascript:
Could someone please help me out on this problem please :)?

All subdomains are redirected tot our main domain www.lelystad.nl and
with javascript redirected to a specific page, eg (Partial):
if (window.location.href == 'http://touristinfo.lelystad.nl' ||
window.location.href == 'http://touristinfo.lelystad.nl/' ||
window.location.href == 'http://www.touristinfo.lelystad.nl' ||
window.location.href == 'http://www.touristinfo.lelystad.nl/') {

window.location.replace("http://www.lelystad.nl/smartsite.shtml?id=5098
0");

}
This works like a charm for all the stated subdomains in this script.
But whenever someone choose to typ another subdomain which is not
stated in the script I would like to use the subdomainprefix in an URL
to feed the searchengine:

http://www.lelystad.nl/smartsite.shtml?id=search&SArea=alm&SThema=0&zoe
kterm=SUBDOMAIN

Dit geeft enige richting, ik heb het niet getest:
(= not tested)

<script type='text/javascript'>

var wloc = window.location.href
var ok = /^http:\/\/www\.lelystad\.nl/i.test(wloc)
var subdom = wloc.replace(/^(www\.)?([^\.]+)\.lelystad.nl*./i,'$2')

if (!ok)
window.location.href =
'http://www.lelystad.nl/smartsite.shtml?id=search&SArea=alm&' +
'SThema=0&zoekterm=' + subdom

</script>
 
S

scriptguru

M@r(o said:
Hello,

Could someone please help me out on this problem please :)?

All subdomains are redirected tot our main domain www.lelystad.nl and
with javascript redirected to a specific page, eg (Partial):
if (window.location.href == 'http://touristinfo.lelystad.nl' ||
window.location.href == 'http://touristinfo.lelystad.nl/' ||
window.location.href == 'http://www.touristinfo.lelystad.nl' ||
window.location.href == 'http://www.touristinfo.lelystad.nl/') {

window.location.replace("http://www.lelystad.nl/smartsite.shtml?id=50980");

}
This works like a charm for all the stated subdomains in this script.
But whenever someone choose to typ another subdomain which is not
stated in the script I would like to use the subdomainprefix in an URL
to feed the searchengine:

http://www.lelystad.nl/smartsite.shtml?id=search&SArea=alm&SThema=0&zoekterm=SUBDOMAIN

TIA
Grtz,
Marco.

I think the JS is not the best choice. Try to use server-side settings.

Val Polyakh
http://trickyscripter.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,129
Latest member
FastBurnketo
Top