Generally, to better relieve server pressure and enhance the friendly aspect of search engines, we generate static pages for the article content.
However, in order to display some information in real time or use dynamic scripts to solve some problems, dynamic page display is required instead of static display of website content.
In this way, the friendly aspect of the search engine has been lost. How can we find an intermediate method between the two, how to enhance the readability of the addresses on your website and enable search engines to quickly include the addresses on your website?
This requires you to beautify the address of your webpage. This produces a pseudo static technology, which is also known as Url Rewriter Rewriting Technology. When we pull a page, the address bar shows the static page form ending with "".html", but the dynamic webpage we actually visit. UrlRewriter is used here.
Many of you may be familiar with the Url rewriting technology provided by many servers. In the past, Apache was the most used. Some servers such as Jboss had some built-in URLs, but their configuration was troublesome, performance is not very good. Now we have a dedicated open-source framework to complete Url rewriting tasks. Today we will introduce UrlRewriteFilter, which is relatively simple to use. UrlRewriteFilter is a Web Filter Used to rewrite URLs, similar to Apache mod_rewrite. Applicable to any Web Application Server (such as Resin, Orion, and Tomcat ). Typical applications use static dynamic URLs to facilitate search engine crawlers to capture your dynamic web pages.
First, let's take a look at the benefits of using Url rewriting for your website.
First:It is conducive to crawling by search engines, because most search engines are still relatively weak in capturing dynamic pages, and they prefer to crawl some static pages. Most of the data on our current page is dynamically displayed. This requires us to turn dynamic pages into static pages, which is conducive to search engine crawling.
Second:This makes it easier for users to understand. Few users care about the addresses of pages on your website, but it is necessary to enhance readability for medium and large websites. This will make your website more perfect.
Third:The implementation of the hiding technology can be achieved through Url rewriting. It will not expose the technology you are using, and provide convenience for fans who want to attack your website.
Fourth:It can be easily reused to improve the portability of websites. If we change the background method, we can ensure that the front-end page does not need to be changed. This improves the portability of the website.
Although it has so many advantages, it also has some disadvantages, because it is implemented through the filter principle, it is thought that there is another access, which may affect the point access speed. This is negligible.
Currently, UrlRewriter has two technical platforms: Java and. NET. Today we are talking about Java applications.
First, let's understand how it works. To put it bluntly, it is a simple Filter. You will soon understand the source code, it is the forward () and sendRedirect () implemented through two common methods in jsp ().
The following describes the simple application of Url rewriting technology:
Step 1: Download The urlrewrite-3.2.0beta.jar package and copy the urlrewrite-3.2.0beta.jar to classpath.
Step 2: Create a urlrewrite. xml configuration file under the WEB-INF directory.
Step 3: Configure UrlRewriteFilter in the web. xml configuration file. Add the following code to the configuration file:Copy codeThe Code is as follows: <! -- Set URL Rewrite in the configuration file -->
<FILTER> </FILTER>
<FILTER-NAME> </FILTER-NAME> UrlRewriteFilter
<FILTER-CLASS> </FILTER-CLASS>
Org. tuckey. web. filters. urlrewrite. UrlRewriteFilter
<FILTER-MAPPING> </FILTER-MAPPING>
<FILTER-NAME> </FILTER-NAME> UrlRewriteFilter
<URL-PATTERN> </URL-PATTERN> /*
<DISPATCHER> </DISPATCHER> REQUEST
<DISPATCHER> </DISPATCHER> FORWARD
Finally, I will briefly introduce the two commonly used configuration rules. The following is a simple URL rewrite. xml configuration snippet. Do not use the Java Naming method to write it as urlRewrite. xml, so that even if you addCopy codeThe Code is as follows: <INIT-PARAM> </INIT-PARAM>
<PARAM-NAME> </PARAM-NAME> confPath
<PARAM-VALUE> </PARAM-VALUE>/WEB-INF/urlRewrite. xml
An error will still be reported when the server is started, because the source code must be all lowercase (urlrewrite. xml) and can only be placed under the WEB-INF.
<! -- L version = "1.0" encoding = "UTF-8 -->
<URLREWRITE> </URLREWRITE>
<! -- Display topic posts -->
<RULE> </RULE>
<FROM> </FROM> ^/forum/thread/(%0-9%%%%%.html $
<TO type = "forward"> </TO>/forum/list. action? Id = $1
<RULE> </RULE>
<FROM> </FROM> ^/forum/thread/(%0-9%%%%%.html? Page = ([0-9] +) $
<TO type = "forward"> </TO>/forum/list. action? Id = $1 & page = $2
All rule configurations are written here. The first common rule is simple rewriting in the station.
<Rule>
<From> </from>
<To type = "forward> </to>
</Rule>
<From> </from>
Write your own access address, which is usually written in a regular expression. <to type = "forward> </to> is the actual access address. For example, our actual access address is: http://www.phome.asia/forum/list.action? Id = 16931 & page = 2 and we want to rewrite it as a http://www.phome.asia/forum/thread/16931.html? Page = 2. This looks much better than what we actually do. We should write like this:Copy codeThe Code is as follows: <RULE> </RULE>
<FROM> </FROM> ^/forum/thread/(%0-9%%%%%.html? Page = ([0-9] +) $
<TO type = "forward"> </TO>/forum/list. action? Id = $1 & page = $2
A Brief Introduction to common Regular Expressions:
Code Description
. Match any character except linefeed
\ W matches letters, numbers, underscores, and Chinese characters
\ S matches any blank space character
\ D matching number
\ B matches the start or end of a word
^ Match the start of a string
$ End of matching string
Commonly used & expressed in. $1, $2 represents the parameter corresponding to the regular expression you configured>/(\ w +. <To type = "forward"> the default value is type = "forward ".
Another common rule is to connect external websites. <To type = "redirect"> is required.Copy codeThe Code is as follows: <RULE> </RULE>
<FROM> </FROM> ^/rss/yahoo \. html $
<TO type = "redirect"> </TO> http://add.my.yahoo.com/rss? Url = http://feed.feedsky.com/MySiteFeed