/    Sign up×
Community /Pin to ProfileBookmark

redirecting based on web address

Hello, I have two domain names, call them [url]www.a.com[/url] and [url]www.b.com,[/url] but only one web host. The web host says I cannot have the two names point to different areas on the server without some complicated billing thing that I don’t understand.

What I’d like to do is use javascript to redirect the user to a specific page depending on what address they are trying to reach.

For example:

[url]http://www.a.com[/url] would go to what is currently [url]www.a.com.[/url]

But if the user tried to go to
[url]http://www.b.com,[/url] the javascript would ideally rerout the user to [url]http://www.a.com/bpage.html[/url] instead of [url]http://www.a.com[/url] which is what it currently does.

Is this possible and reliable?

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@Khalid_AliSep 08.2003 — I don't think JavaScript can do that,its the web server that you may need to configure for this or change a DNS entry in your domain name server......
Copy linkTweet thisAlerts:
@BigJim96Jan 17.2008 — <script type="text/javascript">

if (window.location.href.indexOf("b.com") != -1)
{
location.replace("http://www.a.com/bpage.html")
}
else if (window.location.href.indexOf("c.com") != -1)
{
location.replace("http://www.a.com/cpage.html")
}
else
{
location.replace("http://www.a.com/badpage.html")
}
// -->
</script>
Copy linkTweet thisAlerts:
@LeeUJan 17.2008 — The only problem would be if the person doesn't have JS turned-on. Do you have access to your .htaccess file?
×

Success!

Help @jigidyjim 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.16,
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,
)...