You should know that Microsoft's urlrewrite can rewrite the URL, but it can only rewrite the part after the domain name, rather than the domain name. For example, you can rewrite http: // http://www.abc.com//1234/ override to http://www.abc.com/show.aspx? Id = 1234, but cannot
Http://1234.abc.com/override to http://www.abc.com/show.aspx? Id = 1234.
To achieve this function, the premise is http://www.abc.com/is Pan resolution, and then to modify urlrewriter.
2 files to be modified in total
1. basemodulerewriter. CS
Protected Virtual Void Basemodulerewriter_authorizerequest ( Object Sender, eventargs E)
{
Httpapplication app=(Httpapplication) sender;
Rewrite (App. Request. Path, APP );
}
Change
Protected Virtual Void Basemodulerewriter_authorizerequest ( Object Sender, eventargs E)
{< br> httpapplication app = (httpapplication) sender;
rewrite (App. request. URL. absoluteuri, APP);
}
Replace app. Request. path with 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 " + Sendtourl );
// Rewrite the URL
Rewriterutils. rewriteurl (App. Context, sendtourl );
Break ; // Exit the For Loop
}
}
Change
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 " + Sendtourl );
// Rewrite the URL
Rewriterutils. rewriteurl (App. Context, sendtourl );
Break ; // Exit the For Loop
}
}
Set
String lookfor = "^" + rewriterutils. resolveurl (App. Context. Request. applicationpath, rules [I]. lookfor) + "$ ";
Changed
String lookfor = "^" + rules [I]. lookfor + "$ ";
After completing these two changes, recompile the project and copy the generated DLL to the bin directory.
Then, rewrite the Regular Expression in Web. config.
< Rewriterrule >
< Lookfor > Http: // (\ D +) \. ABC \. com/ </ Lookfor >
< Sendto > /Show. aspx? Id = $1 </ Sendto >
</ Rewriterrule >
Now, you can enter http://1234.abc.com/in the IE address bar to see http://www.abc.com/show.aspx? Id = 1234
The result is
If you encounter problems in practical applications, please referArticle"Modify urlrewrite to rewrite the domain name", you need to pay attention to the problem, hope to help you!
Appendix:
About urlrewriter
Http://www.microsoft.com/china/msdn/library/webservices/asp.net/URLRewriting.mspx