Urlrewrite Rewrite URL detailed
Urlrewrite is the address rewrite that we usually say, and all the users get are the URL addresses that are processed.
Urlrewrite as the name implies, is to rewrite the URL, the user gets all are processed after the URL address, do I think the benefits are three:
One: Improve security, you can effectively avoid some parameter name, ID, etc. completely exposed to the user, if the user randomly lost, if not comply with the rules of the words will return directly to a 404 or error page, which is more than a direct return of 500 or a lot of server error messages better
Two: Beautify the URL, remove those such as *.do suffix name, long parameter string, etc., you can organize their own streamlining to reflect the content of the URL to access the module
Third: More conducive to the search engine revenue, through the URL of some optimization, you can make the search engine better identify with the information included in the site
Use steps
1 Download jar
Official address: http://tuckey.org/urlrewrite/
Download the Urlrewritefilter-4.0.3.jar and add it to the project Lib directory.
2 Configuration Web.xml
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class> org.tuckey.web.filters.urlrewrite.urlrewritefilter</filter-class>
</filter>
< filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</ url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>forward</dispatcher >
</filter-mapping>
3 Configuration Urlrewrite.xml
Add Urlrewrite.xml to the Web-inf directory of the project.
<?xml version= "1.0" encoding= "UTF-8"?> <!
DOCTYPE urlrewrite Public "-//tuckey.org//dtd urlrewrite 3.1//en"
"Http://tuckey.org/res/dtds/urlrewrite3.1.dtd ">
<urlrewrite>
<rule>
<note> The rule means that
requests To/test/status/will Be redirected to/rewrite-status the URL would be
rewritten.
</note>
<from>^/vweb/view/index\-([0-9]+) $</from>
<to>/vweb/view/index.shtml? _vwebid=$1&type=show</to>
</rule>
</urlrewrite>
Summary:
Urlrewrite is a filter, it will be the user's all requests, to comply with the rules to redirect it. The rules in the rule node are used by default to match regular expressions.
When a user accesses a server, the URL is compared to the configuration, and if the rule is met, it is directed to the configuration in the to node below, and the default is forward jump.
A simple analysis of the above regular expression "^/vweb/view/index-([0-9]+)": "Match the start position of the input string" "matches the end position of the input string
The "\" escape character, which means that the following "-" does not have a special meaning, just a simple string.
"([0-9]+)":
' [0-9] ': A string consisting of any data from 0 to 9
"+" matches 1 or more of the characters just before it.
Thank you for reading, I hope to help you, thank you for your support for this site!