How do I point a second domain to a sub-directory or sub-web of my site?

How do I point a second domain to a sub-directory or sub-web of my site?

Normally, domains can only be setup so that they point to the root directory of your web site. However, using ASP code, you can detect which URL a person is browsing to your site with, and redirect them to the appropriate place on your site. Here is some sample ASP code that will do the job. You will want to put this code at the very top of an .ASP page (generally, the default page of the primary domain) before any HTTP tags:
<%
sname = Request.ServerVariables("SERVER_NAME")
sname = ucase(sname)
if InStr(sname,"DOMAIN1") <> 0 then
response.redirect "subdirectory to go to"
elseif InStr(sname,"DOMAIN2") <> 0 then
response.redirect "2nd subdirectory to go to"
end if
%>


--------------------------------------------------------------------------------
Make sure that the domains in the InStr commands are capital letters.
--------------------------------------------------------------------------------

For example, suppose you have two domains, apple.com and banana.com, pointing to the same web site. 
On this site there is an "appledir" subdirectory (or sub-web) and a "bananadir" subdirectory. 
Then the code will look like this:

<%
sname = Request.ServerVariables("SERVER_NAME")
sname = ucase(sname)
if InStr(sname,"APPLE") <> 0 then
response.redirect "appledir"
elseif InStr(sname,"BANANA") <> 0 then
response.redirect "bananadir"
end if
%>

If you have only two domains and you still need the primary domain to point to the root of the site then you can use this code: 

<%
sname = Request.ServerVariables("SERVER_NAME")
sname = ucase(sname)
if InStr(sname,"DOMAIN2") <> 0 then
response.redirect "directory2" 
else
response.redirect "index.html"
end if
%>
You can substitute the "index.html" to whatever your default page is.
  • 4 Users Found This Useful
Was this answer helpful?

Related Articles

Where can I find documentation for ServerObject's AspMail component?

This documentation can be found at: http://www.serverobjects.com/products.html For...

How do I upload files through my web pages?

You can use Software Artisan's SAFileUP. This is an ASP component that allows you to upload files...

What is PageCounter and how do I use it?

About Page Counter PageCounter is an object that counts and displays the number of times a Web...

How do I setup Microsoft Outlook Express to read my e-mail?

Follow these steps: Open Microsoft Outlook Express. From the Tools menu, click...

How do I setup Netscape Messenger to read my e-mail?

Follow these steps: Open Netscape Navigator. Click the Edit menu and then click Preferences......