Loading includes based upon site name
Is it possible to have a script setup that will load a include file based upon site name?
What I want to do is have include file that will load based upon if the domain is like dev.domain or www.domain
In other words,
http://dev.domain.com ----> include file dev.asp
http://www.domain.com ----> include file live.asp
The reason for this is I want to make it easier to deploy asp pages with the minimal amount of changes from Dev to live.
Anyone know if this is possible?
Re: Loading includes based upon site name
The server variable SERVER_NAME will get you the domain. Then you just include the proper file.
Re: Loading includes based upon site name
Code:
<?php
$homepage = "/subdirectory/";
$currentpage = $_SERVER['REQUEST_URI'];
if($homepage==$currentpage) {
include('file you want to include');
}
?>
Re: Loading includes based upon site name
A PHP solution will not work for an ASP implementation.
Re: Loading includes based upon site name
This isn't as straightforward as I first thought. I tried a little test as follows:
Code:
<html>
<head>
<%
Dim IncludeFile
If LCase(Request.ServerVariables("SERVER_NAME"))="dev.domain.com" Then
IncludeFile = "dev.asp"
ElseIf UCase(Request.ServerVariables("SERVER_NAME"))="www.domain.com" Then
IncludeFile = "live.asp"
Else
End If
%>
<!--#INCLUDE FILE=<%=IncludeFile%>-->
</head>
<body>
</body>
</html>
But it failed, I think because Server Side Includes are processed before the ASP.
Can you not simply do a redirect within your ASP? Like this:
Code:
If LCase(Request.ServerVariables("SERVER_NAME"))="dev.domain.com" Then
Response.Redirect Server.MapPath("dev.asp")
ElseIf LCase(Request.ServerVariables("SERVER_NAME"))="www.domain.com" Then
Response.Redirect Server.MapPath("live.asp")
End If
If your include file isn't ASP and is pure JS/HTML, you could load it into the page:
Code:
Set objFSO=CreateObject("Scripting.FileSystemObject")
Set objFile=objFSO.OpenTextFile(Server.MapPath(IncludeFile))
Response.Write objFile.ReadAll
objFile.Close