Last active
August 31, 2022 12:58
-
-
Save nehemiahj/16fa66476d9a83263f1efb4e3b053cb8 to your computer and use it in GitHub Desktop.
Intermediate Redirect Page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ 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