As you should know, Microsoft's urlrewrite can rewrite URLs, but only the parts after the domain name can be rewritten, not the domain name.
For example, http://http://www.115sou.com/qq/can be rewritten as http://www.115sou.com/show.aspx?id=qq
However, you cannot rewrite http://qq.115sou.com/as HTTP://WWW.115SOU.COM/INDEX.ASPX?ID=QQ.
To achieve this function, the precondition is http://www.115sou.com/is pan-analytic, and then to modify the Urlrewriter.
A total of 2 files to be modified
1.basemodulerewriter.cs
protected virtual void Basemodulerewriter_authorizerequest (object sender, EventArgs e)
{
HttpApplication app = (HttpApplication) sender;
Rewrite (app. Request.path, app);
}
Switch
protected virtual void Basemodulerewriter_authorizerequest (object sender, EventArgs e)
{
HttpApplication app = (HttpApplication) sender;
Rewrite (app. Request.Url.AbsoluteUri, app);
}
is to apply the app. Request.path replaced the app. Request.Url.AbsoluteUri
2.modulerewriter.cs
for (int i = 0; i < rules. Count; i++)
{
Get the pattern to look for, and Resolve the URL (convert ~ into the appropriate directory)
String lookfor = "^" + rewriterutils.resolveurl (app. Context.Request.ApplicationPath, Rules[i]. LookFor) + "$";
Create a Regex (note that IgnoreCase is set)
Regex re = new regex (lookfor, regexoptions.ignorecase);
See if a match is found
if (re. IsMatch (Requestedpath))
{
Match found-do any replacement needed
String sendtourl = Rewriterutils.resolveurl (app. Context.Request.ApplicationPath, Re. Replace (Requestedpath, Rules[i]. SendTo));
Log rewriting information to the Trace object
App. Context.Trace.Write ("Modulerewriter", "rewriting URL to" + Sendtourl);
Rewrite the URL
Rewriterutils.rewriteurl (app. Context, Sendtourl);
Break Exit the For Loop
}
}
Switch
for (int i = 0; i < rules. Count; i++)
{
Get the pattern to look for, and Resolve the URL (convert ~ into the appropriate directory)
String lookfor = "^" + rules[i]. LookFor + "$";
Create a Regex (note that IgnoreCase is set)
Regex re = new regex (lookfor, regexoptions.ignorecase);
See if a match is found
if (re. IsMatch (Requestedpath))
{
Match found-do any replacement needed
String sendtourl = Rewriterutils.resolveurl (app. Context.Request.ApplicationPath, Re. Replace (Requestedpath, Rules[i]. SendTo));
Log rewriting information to the Trace object
App. Context.Trace.Write ("Modulerewriter", "rewriting URL to" + Sendtourl);
Rewrite the URL
Rewriterutils.rewriteurl (app. Context, Sendtourl);
Break Exit the For Loop
}
}
Will
String lookfor = "^" + rewriterutils.resolveurl (app. Context.Request.ApplicationPath, Rules[i]. LookFor) + "$";
Changed it.
String lookfor = "^" + rules[i]. LookFor + "$";
After completing these 2 changes, recompile the project and copy the resulting DLL to the bin directory.
And then write the rewrite regular in Web. config.
<RewriterRule>
<lookfor>http://(\d+) \.115sou\.com/</lookfor>
<SendTo>/show.aspx?id=$1</SendTo>
</RewriterRule>
Well done, you enter http://shouji.115sou.com/in the IE Address bar, you can see Http://www.115sou.com/index.aspx?id=shouji
The results.
UrlRewriter.dll pseudo-static implementation of two-level domain name Pan-resolution