UrlRewrite url rewrite detailed explanation
UrlRewrite is what we usually call address rewriting, and all the users get are processed URL addresses.
As the name suggests, urlrewrite means rewriting the URL. All the users get are processed URL addresses. I think there are three benefits to doing this:
1: Improve security and can effectively avoid the complete exposure of some parameter names, IDs, etc. to the user. If the user simply scatters, if the rule does not meet the rules, it will directly return a 404 or an error page. This is much better than directly returning 500 or a lot of server error messages.
2: Beautify the URL, remove the suffix names such as *.do, long parameter strings, etc., and you can organize and streamline the URLs that can better reflect the content of the access module.
3: It is more conducive to search engine revenue. Through some optimization of URLs, search engines can better identify and include website information.
Steps to use
1 Download jar
Official address: http://tuckey.org/urlrewrite/
Download urlrewritefilter-4.0.3.jar and add it to the project lib directory.
2Configure 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 Configure 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 will be rewriteten. </note> <from>^/vweb/view/index/-([0-9]+)$</from> <to>/vweb/view/index.shtml?_vwebid=$1&type=show</to> </rule></urlrewrite>
summary:
urlrewrite is a urlrewriter. It will take into account all user requests and redirect them if they comply with the rules. The rule from in the rule node uses regular expressions to match by default.
When the user accesses the server, the URL will be compared with this configuration. If the rules are met, it will be redirected according to the configuration in the to node below. The default is forward jump.
A brief analysis of the above regular expression "^/vweb/view/index-([0-9]+)": "" matches the start position of the input string "" matches the end position of the input string
The "/" escapes the character, indicating that the "-" after it has no special meaning, it is just a simple string.
“([0-9]+)”:
"[0-9]": The string "+" composed of any data in 0 to 9 matches 1 or more of the characters that are exactly before it.
Thank you for reading, I hope it can help you. Thank you for your support for this site!