In the daily website access, the dynamic address will be converted to pseudo-static address.
For example: Access to the news column/col/1/, which is the original address, if such access, not conducive to search engine retrieval included, while security is not very good.
After the transformation:
/col/1.html.
Transformation method:
1. Add Urlrewritefilter
<Dependency> <groupId>Org.tuckey</groupId> <Artifactid>Urlrewritefilter</Artifactid> <version>4.0.4</version></Dependency>
2. Configure Beans
Importjava.io.IOException;ImportJavax.servlet.FilterConfig;Importjavax.servlet.ServletException;ImportOrg.springframework.beans.factory.annotation.Value;Importorg.springframework.context.annotation.Configuration;ImportOrg.springframework.core.io.Resource;Importorg.tuckey.web.filters.urlrewrite.Conf;ImportOrg.tuckey.web.filters.urlrewrite.UrlRewriteFilter; @Configuration Public classUrlrewritefilterconfigextendsUrlrewritefilter {Private Static FinalString url_rewrite = "Classpath:/urlrewrite.xml"; //Inject the Resource from the given location@Value (url_rewrite)PrivateResource Resource; //Override The Loadurlrewriter method, and write your own implementation protected voidLoadurlrewriter (Filterconfig filterconfig)throwsservletexception {Try { //Create a Urlrewrite Conf object with the injected resourceConf Conf =NewConf (Filterconfig.getservletcontext (), Resource.getinputstream (), Resource.getfilename (),"@@[email protected]@"); checkconf (conf); } Catch(IOException ex) {Throw NewServletexception ("Unable to load URL rewrite configuration file from" +Url_rewrite, ex); } }}
Reference URL: http://blog.jdriven.com/2016/02/urlrewritefilter-load-configuration-with-spring-resourceloader/
3. Configure Urlrewrite.xml
<?XML version= "1.0" encoding= "Utf-8"?><!DOCTYPE urlrewrite Public "-//tuckey.org//dtd urlrewrite 4.0//en" "http://www.tuckey.org/res/dtds/urlrewrite4.0 . DTD "><Urlrewrite> <!--Column Home - <Rule> < from>^/col/(\w+) \.html$</ from> < to>/col/$1/</ to> </Rule> <!--Column List page, note that there is no add $ after HTML, because there are several parameters - <Rule> < from>^/col/list/(\w+)/(\w+) \.html</ from> < to>/col/list/$1/$2/</ to> </Rule> <!--Article details page - <Rule> < from>^/art/(\w+) \.html$</ from> < to>/art/$1/</ to> </Rule> <!--static Web page - <Rule> < from>^/static/(\w+) \.html$</ from> < to>/static/$1/</ to> </Rule></Urlrewrite>
For configuration instructions, please refer to: http://blog.163.com/zhangmihuo_2007/blog/static/27011075201351433716225/
At this point the configuration is complete, start the test, pay attention to the red box, instructions loaded urlwrite.
Visit the page below and succeed!
URL rewrite in springboot (urlwrite)