Forum Moderators: coopster & phranque

Message Too Old, No Replies

Recognizing Domain Aliases and displaying proper web page

How can I recognize when one of my domain aliases retrieves the main page

         

MichaelEKauffman

10:22 pm on Sep 1, 2001 (gmt 0)

10+ Year Member



What I want to do is recognize when a domain alias is being used so that instead of loading the home page for the viewer to see the viewer will automatically be redirected to the appropriate page

click watcher

11:07 pm on Sep 1, 2001 (gmt 0)



hi if you're on win server you can use asp code on the home page ... put it above all tags ...

<%
sname = Request.ServerVariables("SERVER_NAME")
sname = ucase(sname)
if InStr(sname,"DOMAIN_ALIAS") <> 0 then
response.redirect "alias-directory"
elseif InStr(sname,"DOMAIN_ALIAS2") <> 0 then
response.redirect "alias-directory2"
end if
%>

be sure to use capital letters,
if your on nix someone else will have to help you.

MichaelEKauffman

11:22 pm on Sep 1, 2001 (gmt 0)

10+ Year Member



Thanks for the quick reply! We do not host our website but I will assume for now it's a win server. The asp code is new to me! where can I go to understand what you typed is so I know what variables do what and exactly what gets entered into where

MichaelEKauffman

11:45 pm on Sep 1, 2001 (gmt 0)

10+ Year Member



I just did some digging about the hosting company. They are running Apache on Compaq TruUNIX 5.0a using TruCluster. It runs on multiple Compaq AlphaServers. They can support CGIs in UNIX binary (for Digital UNIX, OSF, and Tru64 UNIX), UNIX Shell Scripts, Perl, and PHP (an embedded HTML language). They do not support Windows NT scripts such as ASP and VBScript. They also do not support JSP, Cold Fusion, and MySQL.

toadhall

4:28 am on Sep 2, 2001 (gmt 0)

10+ Year Member



Michael,
You could use this PHP script. It simply reads the host name and redirects the user accordingly.

<?

$host = getenv(HTTP_HOST);

if ($host == "alias1.domain.com") {
header("Location: [domain.com...]
}

if ($host == "alias2.domain.com") {
header("Location: [domain.com...]
}

if ($host == "alias3.domain.com") {
header("Location: [domain.com...]
}

?>

I'm only guessing this is what you need. Hope it helps.

4eyes

9:01 am on Sep 2, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Interesting - this could come in useful for me.

Anyone know what impact this would have on spiders and ranking?

ggrot

1:56 pm on Sep 2, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The hard server redirect (done with the Location: header) can't be good for rankings. I would suggest using .htaccess and showing different content instead of redirecting to a different URL.

MichaelEKauffman

2:50 pm on Sep 2, 2001 (gmt 0)

10+ Year Member



Thanks toadhall! Your script was placed in my cgi-bin and I named it redirect.php and also edited for the appropriate domains. Chmod was also set to 770. What do I need to do in my index.htm file to get everything working now?

gethan

8:35 am on Sep 3, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This will depend on the way the hosting company has set things up but a standard approach is to do the following:

Copy redirect.php to your htdocs root (where index.htm lives). Test it in this new directory - does it do what you want?

Rename it index.php --- and the rename index.htm to index-old.htm or something.

As for spiders -- not exactly sure what would happen. I think it would be better for page ranks to do something in php like;

<?
$host = getenv(HTTP_HOST);
if ($host == "alias1.domain.com") {
print "custom content for alias 1"; # Open the file in dir1 and print it.
}
if ($host == "alias2.domain.com") {
print "custom content for alias 2";
}
?>

All links from this page would then be to the sub dirs.

One other thing is to check that your hosting providers don't offer this as a service already -- it is more efficient for the web server to do this work.

Good luck ;)

jatar_k

9:04 am on Sep 3, 2001 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You could also change those server aliases to each point to the appropriate pages within your site. It would probably be easier to maintain and a lot faster for the user. You would need to get it set up by your host though.

MichaelEKauffman

12:38 pm on Sep 3, 2001 (gmt 0)

10+ Year Member



Thanks everybody for the help! All of the alias domains are already pointed to the main domain: no matter which alias you click on or type in you will always end up at the main domain homepage (index.htm). I did not know you could go one step further and have the host point them to a specific page within the main website!!!!!

MichaelEKauffman

1:36 pm on Sep 4, 2001 (gmt 0)

10+ Year Member



Everything worked great when I ended up going with the PERL script below. The file was placed in the root directory as index.cgi and the original index.htm file was renamed home.htm. Will this process using the PERL script have any effect on Spiders and page ranks?

#!/usr/bin/perl
# Domain Name Redirect To URL
#

%Domain_Names = (
"domain_alias1.com" => "http://domain_alias1.com/proper_page1.htm",
"domain_alias2.com" => "http://domain_alias2.com/proper_page2.htm");

$Default_URL = "http://www.main_domain.com/home.htm";

foreach $line (keys(%Domain_Names)) {
if ($ENV{'HTTP_HOST'} =~ /$line/i) {
print "Location: $Domain_Names{$line}\n\n";
exit;
}
}

print "Location: $Default_URL\n\n";

Thanks again everybody for all of your expertise!!!