/    Sign up×
Community /Pin to ProfileBookmark

redirect using document.referrer

I’m working on a site which has 2 domain names pointing at it – [url]www.sitename.co.uk[/url] and [url]www.sitename.ie.[/url] All the pages are identical across the 2 sites apart from the home pages. I’ve set up a redirect script so that if a user clicks on the home page link they get the appropriate home page depending on whether they’ve viewing the .co.uk or .ie site.

This is the script and it works fine:

if (document.referrer.indexOf(‘sitename.ie’) > -1)
location.href = ‘http://www.sitename.ie/index1.htm
else
location.href = ‘http://www.sitename.co.uk/index2.htm

I’ve actually set it up on ‘index.htm’ and there’s nothing else on that page apart from the script. The problem is that it doesn’t work if the user simply types the domain name into the browser – if he types in ‘www.sitename.ie’ he still gets the .co.uk home page.

Is there a simple fix for this? I hope so because I’m by no means a javascript expert!

Bob.

PS I also wonder about the wisdom of having an ‘index.htm’ page with only a script on it – how will search engines react to this? Maybe there’s a better way to achieve what I need?

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@artemisSep 23.2004 — [font=technical][size=3]for a start I wouldn't use JavaScript as not everyone has it endabled.

is suggest you use a [i].htaccess[/i] file and use the [i]mod_rewrite[/i] functions so alter the url depending on the location name.[/size]
[/font]
Copy linkTweet thisAlerts:
@tintin99authorSep 23.2004 — sounds good...but isn't mod_rewrite an Apache function? I'm not sure if it's an Apache server we're on.

Bob.
Copy linkTweet thisAlerts:
@artemisSep 23.2004 — [font=technical][size=3]lol sorry thats an excellent point, damn my assumptions.

hmm I dont know then, see if anyone else has anyother suggestions...[/size]
[/font]
Copy linkTweet thisAlerts:
@Willy_DuittSep 23.2004 — Did you try: [i]location.host[/i]?
Copy linkTweet thisAlerts:
@tintin99authorSep 23.2004 — I assume you meant simply replacing 'document.referrer' with 'location.host'? Anyway I did and it works!!!!

Thanks a lot!

Bob.
×

Success!

Help @tintin99 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...