Forum Moderators: open
"/index.php" or $requrl=="/index.htm" or $requrl=="/index.html" or $requrl=="/index.shtml" or $requrl=="/index.asp" or $requrl=="/index.aspx" or $requrl=="/default.asp" or $requrl=="/default.htm" or $requrl=="/index.cfm" or $requrl=="/index.pl"This can be simplified using a regular expression which will parse a LOT faster:
"/(index|default)\.(php|s?html?|aspx?|cfm|pl)"
But the following wouldn't be effected if my reading of the code is correct.
"http://www.example.com/subdir/index.php" would still show up and not be redirected.
//Assigns the current request URL to a local variable
System.Uri Address = this.Request.Url;
//gets the Hostname from the url
string host = Address.Host.ToLower();
//replaces hostname with the one we want to use.
//This makes it so we can force the domain name
//to be what we want always.
host = Address.AbsoluteUri.Replace(host, "www.example.com");
//creates a new URI with based on modified URI
Address = new Uri(host);
//This is where you do your checks for page level items
System.Text.RegularExpressions.Match regxmatch;
string Match = ""; //<-- this is what ever expression you are checking for
regxmatch = System.Text.RegularExpressions.Regex.Match(Address.AbsolutePath, Match, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
if (regxmatch.Success == true)
{
//You modify the Address URI class based on sucessfull match
//to repoint it where you need it to go
}
//Compares the Current modified Address to the Original and
//if they are different does a perm redirect.
if (Address.AbsoluteUri != this.Request.Url.AbsoluteUri)
{
this.Response.Status = "301 Moved Permanently";
this.Response.AppendHeader("Location", Address.AbsoluteUri);
this.Response.End();
return;
}