Let's take a moment to look at some URLs on the website. Have you found something similar to http://yoursite.com/info/dispEmployeeInfo.aspx? EmpID = 459-099 & type = summary URL? Alternatively, you may move a series of web pages from one directory or website to another directory or website. As a result, visitors who have used the old URL as a bookmarks will be disconnected. In this article, we will learn how to associate http://yoursite.com/info/dispEmployeeInfo.aspx? EmpID = 459-099 & type = summary is replaced with a URL similar to a http://yoursite.com/people/sales/chuck.smith, using URL rewriting to abbreviated lengthy URLs as rich meaningful and easily remembered URLs. We will also learn how to rewrite a URL to create a smart 404 error.
URL rewriting is the process of intercepting incoming Web requests and automatically redirecting requests to other resources. During URL rewriting, the request is usually checked and redirected to another URL Based on the URL value. For example, when a website is reorganized and all the webpages in the/people/directory are moved to the/info/employees/directory, you may want to use URL rewriting to check whether the Web request points to a file in the/people/directory. If the request points to a file in the/people/directory, you may want to automatically redirect the request to the same file in the/info/employees/directory.
Using traditional ASP, the only way to rewrite a URL is to write an ISAPI filter or buy a third-party product that provides the URL rewriting function. However, Microsoft? ASP. NET, you can easily create your own URL rewriting software in many ways. This article discusses various technologies that can be used by ASP. NET developers to rewrite URLs, and then discusses some actual use cases of URL rewriting. Before going into the technical details of URL rewriting, let's take a look at some daily scenarios that can be rewritten using URL.
Common URL rewriting usage
When creating a data-driven ASP. NET Website, a single web page is usually generated, which displays a subset of Database Data Based on query string parameters. For example, when designing an e-commerce site, one of your tasks is to allow users to browse products for sale. To this end, you can create a page named displayCategory. aspx that displays products of a given category. You can query string parameters to specify products of the specified type. That is, if you want to browse the Widget products for sale and the CategoryID of all Widget products is 5, you can visit the following url: http://yousite.com/displayCategory.aspx? CategoryID = 5.
There are two drawbacks to creating a website with such a URL: first, from the end user's perspective, the URL http://yousite.com/displayCategory.aspx? CategoryID = 5 is messy. Availability expert Jakob Neilsen recommends that you follow the following criteria to select a URL: Short, easy to type, and to see the structure of the site.
You can delete a part of a URL to browse the site.
I also want to add a standard, that is, the URL should be easy to remember. URL http://yousite.com/displayCategory.aspx? CategoryID = 5 does not comply with any Neilsen standards and is not easy to remember. It is required that you enter the query string value, which makes it very difficult to type the URL, in addition, only experienced Web developers who know how to query string parameters and their name/value pairs can delete URLs ".