I own several domain names on which I have the same layout and content. I would like to differentiate the sites a bit by having personalized headers and footers for each site.
So I thought about having a script that will detect what domain name it's called from and display the according header and footer. (or maybe 2 scripts, one for header and another one for footer).
This way, I could avoid duplicating content that's basically the same... but still have personalized headers and footers for each site/domain name.
I hope you undertood what I was looking for... English is not my native tongue as you must have noticed... ;) Anyway, I was wondering if you guys could point me to some website, or to some resource that could help me reach my goal?
I believe it should be a pretty easy script for somebody in the know... Something like: if domain name=abcd.com, then header=abcd-header.html, if domain name=efgh.com then header=efgh.html, ...
Thanks a lot for your help!
Bresso
# The domain name the server is responding on
$hostname = $ENV{'HTTP_HOST'};
# The header and footer files are based on the following
# directory structure. Change to suit your needs.
$header = "templates/$hostname/header.txt"
$footer = " templates/$hostname/footer.txt"
# Print the header
&head_foot ($header);
#insert rest of html here
# Print the footer
&head_foot($footer);
# The sub routine to read the header or footer files and
# print.
# N.B. Make sure you have already sent a content type
# e.g text/html
sub head_foot {
my ($headerorfooter) = @_;
open (IN, "< $headerorfooter") ¦¦ die "Could not open $header file\n$!";
my @lines = <IN>;
# process each line
foreach my $line(@lines) {
print $line;
}
}
Let's presume your site is coded in Perl (which I presume it is as you posted in the Perl forum)
Simply save the text in the post above in a file called headandfoot.pm and place it in the same directory as your main script.
Then place a line at the top of your script saying
require headandfoot.pm;
$hostname = $ENV{'HTTP_HOST'}; # The header and footer files are based on the following
# directory structure. Change to suit your needs.
$header = "templates/$hostname/header.txt"
$footer = " templates/$hostname/footer.txt"
Then wherever you want the header to appear place
&head_foot ($header);
or footer to appear
&head_foot ($footer);
If you site is in plain html let me know and I'll adapt this code to work via an SSI
Jason
I thought that the Spiders disregarded (couldn't see) scripts?
If this is the case, I don't think that it will solve the duplicate content problem. I am just learning, so if I am incorrect on this, please forgive my ignorance.
I have just, today, started to learn about scripting.
Where do I start?
eTN