How to play URL Rewriting

URL Rewriting, this seems familiar, and felt very strange technology, information security and has been with the pace of SEO (Search Engine Optimization), and gradually affect every Web Developer, no matter which technology you go (ASP, ASP.NET, PHP, JSP, Ruby, Perl, ...), basically hard not to pay attention to it, because it can actually help you a lot. Just a REST URL pattern, you can make a lot of people to our eyes.


URL Rewriting, this seems familiar, and felt very strange technology, information security and has been with the pace of SEO (Search Engine Optimization), and gradually affect every Web Developer, no matter which technology you go, basically hard not to to pay attention to it, because it can actually help you a lot. Just a REST URL pattern, you can make a lot of people to our eyes.

Imagine, if you have a branch site URL is long so pretty:
http://www.abc.com.tw/myblog/blog.aspx?id=18472938290&postdate=20090404

Or so good-looking:
http://www.abc.com.tw/myblog/2009/04/04/ 18472938290.aspx

Or, if the user can enter the URL of this way:
http://www.abc.com.tw/productinfo/MP3

He wants to list the search catalog of MP3 Player, users still have to play:
http://www.abc.com.tw/productinfo/search.aspx?keyword=MP3 this URL?

I think people have a concept of marketing or consumer behavior is concerned, the answer is quite clear.

URL Rewriting strengths is the URL appearance, converted into internal URL that looks to do the deal, let's continue to use the internal URL, but also allows an external URL with affinity, thus becoming the URL Rewriting now one of the technical site developers need to know, and now actually has a lot of URL Rewriting module can be used, for example UrlRewriting.Net this package, or in IIS 7.0 URL Rewriting module and so on.

However, if we can own were born, then, would be a better understanding of what URL Rewriting yes, but also for URL Rewriting module on the network, will be a more accurate grasp of force (hereinafter to ASP.NET technology as the main explanation, other languages Please refer to the manual to find out the corresponding function).

First of all, URL Rewriting URL as external and internal requirements of the converter, it needs to filter all of the URL, to perform re-turning action, so it is more suitable for survival in the implementation of Web Server in order to ASP.NET, using HTTP Module can handle this work (HTTP Handler less suitable).

Then who set the processing HttpApplication.BeginRequest or HttpApplication.AuthorizeRequest events (most of the modules are processed HttpApplication.AuthorizeRequest event):

public void Init(HttpApplication context)
{
    context.AuthorizeRequest += new EventHandler(AppAuthorizeRequest);
}

And then in the event handler, call HttpApplication.Context.RewritePath () to:

public void AppAuthorizeRequest(object sender, EventArgs e)
{
    (sender as HttpApplication).Context.RewritePath("~/MyHandler.aspx");
}

Then, in Web.config, this module onto system.web / httpModules settings, if IIS 7.0, will have provided system.webServer / modules in.


   
   
       
   

Then execute the Web Application, regardless of which path you enter the URL, will be directed to MyHandler.aspx in (of course, your project must have MyHandler.aspx this page).

URL Rewriting In fact, technically that would be it, through HttpApplication.Context.RewritePath will be asked to specify the URL of the page spread () to deal with, but in fact the development, URL Rewriting have to consider the fact many:

  1. Since each URL will be processed, and that if the URL points to a picture file, scripts or other resources to how to deal with?
  2. Is there a special path to exclude?
  3. The implementation of URL Rewriting, how to format the URL will be designed to meet the needs?
  4. Because when the URL is rewritten,
    The action attribute will react URL internal, rather than external URL, how to deal with this time?
  5. URL Rewriting performance is required, because it has to deal with each URL requirements, rather than selectivity does not handle.

In addition, URL is not necessarily hard to do Rewriting, part of the need to exclude you do not need to do Rewriting, or you have to do is some form of URL redirection (HTTP 302), you can also output directly to the browser HTTP 302 message requires discouraged guide can, remember, do not add too much in the URL Rewriting in judgment conditions, and do not do too time-consuming thing in the URL Rewriting in, it will only slow down the processing speed of the URL (such as database access data but also even such a thing).

Original: Big Box  how to play URL Rewriting


Guess you like

Origin www.cnblogs.com/petewell/p/11518172.html