URLWRITE view Rewriting Technology and urlwrite view Rewriting

Source: Internet
Author: User

URLWRITE view Rewriting Technology and urlwrite view Rewriting

UrlRewrite is the address rewriting. All the URLs you get are processed URLs, similar to Apache mod_rewrite. Converting our dynamic webpage addresses to static ones, such as html and shtml, can also hide the real path of the webpage.
It has the following features:
1. Improved security and hidden URLs
2. Beautifying URLs, facilitating search engine revenue and increasing traffic

Download the jar package
Web: http://central.maven.org/maven2/org/tuckey/urlrewritefilter/

You can see the jar packages of various versions of urlwritefilter.
Import the Jar package to the project after it is downloaded.

Create a urlrewrite. xml file

<? 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>
<From>/([a-za-z?##.html </from>
<To last = "true">/$ 1.jsp</to>
</Rule>
</Urlrewrite>
// The dtd file has only two digits, for example, 4.0.2/4.0.3/4.0.4, and only urlrewrite4.0.dtd

Rule is a url rewriting rule, from is the displayed address, to is the actual address of the ing, $1 is the rewriting parameter, and its value is one-to-one correspondence with the regular expression in from, there can be multiple regular expressions that match the regular expression (). The regular expression ^ specifies the character string to start and $ indicates the end. <rule> <from> /(. *)/login.html </from> <to type = "forward">/yui/login.html? Name = $1 </to> </rule>
<Rule>
<From> ^/user/([a-z] +)/([0-9] +) $ </from>
<To>/index. jsp? Nickname = $1 & amp; age = $2 </to>
</Rule>
For example, the actual request url of http: // localhost: 8080/app/abc/login.html is http: // localhost: 8080/app/yui/login.html? Name = abc
The more advanced the rule, the more effective it takes.

Configure the web. xml file

<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>

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.