Skip to content

Instantly share code, notes, and snippets.

@nehemiahj
Last active August 31, 2022 12:58
Show Gist options
  • Save nehemiahj/16fa66476d9a83263f1efb4e3b053cb8 to your computer and use it in GitHub Desktop.
Save nehemiahj/16fa66476d9a83263f1efb4e3b053cb8 to your computer and use it in GitHub Desktop.
Intermediate Redirect Page
<%@ Page Language="C#" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>redirecting...</title>
</head>
<body>
</body>
</html>
<script language="c#" runat="server">
string GetUrl(string text, string search, string replace)
{
text = text.Replace("url=", "");
int pos = text.IndexOf(search);
if (pos < 0)
{
return text;
}
return text.Substring(0, pos) + replace + text.Substring(pos + search.Length);
}
public void Page_Load(object sender, EventArgs e)
{
var qs = Request.ServerVariables["QUERY_STRING"];
if (!System.String.IsNullOrEmpty(qs) && !System.String.IsNullOrEmpty(qs.Replace("url=", "")))
{
var url = GetUrl(qs, "&", "?");
if (!System.String.IsNullOrEmpty(url))
{
Sitecore.Diagnostics.Log.Info("IIS Redirect: " + Request.ServerVariables["HTTP_X_ORIGINAL_URL"] + " --> " + url, this);
System.Web.HttpContext.Current.Response.ClearHeaders();
System.Web.HttpContext.Current.Response.Status = "301 Moved Permanently";
System.Web.HttpContext.Current.Response.StatusCode = 301;
// #### To Cache the redirects in Proxy/CDN for 60 seconds but no cache in Client Browser
System.Web.HttpContext.Current.Response.AppendHeader("Cache-Control", "public, max-age=0, s-maxage=60");
// #### Change the Cache-Control as per your need. No Cache here ####
// System.Web.HttpContext.Current.Response.AppendHeader("Cache-Control", "no-cache, max-age=0, must-revalidate");
System.Web.HttpContext.Current.Response.AddHeader("Location", url);
System.Web.HttpContext.Current.Response.End();
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment