Abstract:
I have explained the knowledge of URL rewriting. I used Asp.net to implement the method of second-level domain name rewriting. I have summarized some questions about rewriting and provided several examples. Code .
No writing technology for a long timeArticleIf you do not understand, read more articles, sweat, or reply after the article (this is the most effective method). I will try my best to help you answer your questions.
I should know what a second-level domain name is when I come to this article, so I won't talk nonsense. But before the discussion, I should first understand an ideological problem.
The problem that many of my friends have been confused (I have been confused a few days ago) is that after I type an address, how can this URL be rewritten?
Step 1: What happened when I typed an address in a browser, such as a http://love.kerry.com, and clicked enter?
To simplify the problem, I will explain it as follows:
Step 2: first, the entered address is parsed and finally comes to a Web server. to IIS for processing. in. in the net world, IIS will send such requests to a web processor for processing. Finally, the Web processor returns the processing results to the browser and displays them to users.
Please do not ignore this problem. Everything in step 2 is done on the server side. during these operations, the address on the browser of the user side will not change. even if the web processor returns the processing result, the above address will not change.
The URL entered at the beginning serves only as a knock-on interface. After the door is knocked out, the function is completed. Only your eyes can see the address, the browser, the server does not know the address.
The problem that we need to understand is that URL rewriting is only an insider situation that web developers know, and users do not know what happened, he thinks that the address he typed is the result displayed on the screen. that is to say, we control the content to be displayed behind the scenes.
Next, we should consider how to control the displayed content?
From the process mentioned above, it is obvious that you need to work in the Web processor step.
One of the simplest considerations is that the user typed in a simple address without any parameters, http://love.kerry.com then we changed this address toProgramRequired address with parameters, http://kerry.com? Lover = notus.
This step is called URL rewriting.
In. Net terminology, We need to register an httpmodule for the application to process specific URLs.
Register httpmodule, in Web. config,
Processing URL, In the httpmodule program we provide
It is basically equivalent to a program like this.
// Use our httpmodule program to capture the original URL
String originalurl = "http://love.kerry.com ";
// Process the original URL and get the final required URL. The value is http://kerry.com? Lover = notus
String finalurl = rewrite (originalurl );
// Context re-sends the URL internally to IIS for processing
Context. rewritepath (finalurl );
Next, we will rewrite the URL.
Step 1: Determine the URLs to be overwritten, that is, the rewrite rules.
Step 2: Compile the httpmodule Handler
Step 3: Integrate the compiled httpmodule into the web program and start working.
The above is the basic knowledge of URL rewriting, and the process of using URL rewriting to implement second-level domain names is the same. because both the second-level domain name and third-level domain name are URLs. as long as we intercept this URL address, we can start to process it.
These jobs are troublesome, but some people on the Internet have written such a program for us. refer to the following article:
Http://www.microsoft.com/china/m... t/urlrewriting. mspx
Http://www.cnblogs.com/jzywh/archive/2005/09/29/246650.html
Http://www.cnblogs.com/jzywh/archive/2006/02/20/334004.html
The article is over.