Everyone should know that Microsoft's URLREWRITE can rewrite the URL, but can only rewrite the part of the domain name, and cannot rewrite the domain name, such as:
HTTP: //
Www.abc.com/1234/ Rewriting
http://www.abc.com/show.aspx?id=1234 but cannot be
Http://1234.abc.com
http://www.abc.com/show.aspx?id=1234.
To achieve this function, the prerequisite is
Www.abc.com is generally analyzed, and then it is necessary to modify URLREWRITER.
A total of 2 files to be modified
1.BasemoduleRewriter.cs
protected
Virtual
Void
BasemoduleWriter_authorizeRequest
Object
Sender, Eventargs E)
{Httpapplication app = (httpApplication) Sender; Rewrite (app.request.path, app);
Change to
protected
Virtual
Void
BasemoduleWriter_authorizeRequest
Object
Sender, Eventargs E)
{Httpapplication app = (httpapplication) sender; Rewrite (app.request.url.absoluteuri, app);
That is to replace App.Request.path with app.request.url.absoluteuri
2.ModuleWriter.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}}
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}}
String Lookfor = "^" Rewriterutils.Resolveurl (app.context.request.ApplicationPath, rules [i] .lookfor) "$";
Changed
String Lookfor = "^" Rules [i] .lookfor "$";
After completing these 2 changes, recompile the project, copy the generated DLL to the bin directory.
Another is written in Web.Config.
<
Rewriterrule
>
<
Lookfor
>
http: // (/ d ) /.abc/.com
Lookfor
>
<
Sendto
>
/SHOW.ASPX?id= $ 1
Sendto
>
Rewriterrule
>
Ok, I am gone, you entered in IE address bar.
Http://1234.abc.com, you can see
http://www.abc.com/show.aspx?id=1234
Outcome
If you encounter problems in practical applications, please see the article "Modify URLREWRITE to rewrite the domain name" need to pay attention, I hope to help you!
Attachment:
Related information of URLREWRITER
http://www.microsoft.com/chna/msdn/library/webservices/asp.net/urlrewriting.mspx
This article background:
Http://jzywh.cnblogs.com/archive/2005/09/29/24650.html
Many friends on the Internet saw this article, do it according to my method, but still didn't get the desired effect, in fact, some problems need to pay attention, I only put forward the most important way to solve this problem. The content, some friends may encounter some problems in practical use. It is actually possible to solve according to their own experience, I should solve it, I am here to list some points to help you solve problems quickly.
Domain name analysis
Enter the domain name
Http://1234.abc.com, the browser prompts cannot be found. First, you should confirm that your domain name supports the extension-name resolution, which is to let all the second level, the third-level domain name points to your server. Second, to ensure that your site is the default site on the server, it is the 80-port host header, you can directly use IP to be accessed.
Http://1234.abc.com, you want to prompt your site's error message, either execute the URLREWRITE you defined correctly, or display the home page of your site.
2. Cannot perform overwritten problems
If you confirm that your domain name resolution is correct, but still can't rewrite, access
Http://1234.abc.com will prompt
Path "/" can't find ...,
If this is this, you first add ASPNET_ISAPI's wildcard application mapping (
This step is required, Sorry! No comes out in the last article).
Operation method: IIS Site Properties -> Main Directory -> Configuration
Click insert button
Select or enter C: /Windows / Microsoft.Net/framework/v1.1.4322/ASPNET_ISAPI.DLL
Cancel the hook before the "confirmation file exists".
determine
Come to visit
Http://1234.abc.com should have no problem.
3. The default home page is invalid because the request is directly handed over to the ASP.NET processing, the default home page defined by IIS will fail, this situation occurs:
access
Http://www.abc.com cannot access the home page,
http://1234.abc.com/default.aspx can be accessed.
To solve this problem, please settle your problem in Web.Config in Web.Config .. You can solve the problem.
OK, I list the solution to the problem that should be universally appeared. If you have there, I have no problems listed here and you can't solve it, please ask questions here or send me an email or add me QQ.
Original address:
Http://www.cnblogs.com/jzywh/archive/2005/09/29/24650.html
Http://www.cnblogs.com/jzywh/archive/2006/02/20/seconddomainurlrewriter.html