Many web sites have some more personalized access to the domain name, such as: http://www.xxx.com/u/pp point Open can see PP's personal homepage, this address is easier to remember, that today to talk about the implementation of this technology.
1. Using Java as the development language to implement this kind of address rewriting requires you to introduce a jar package: Urlrewrite-3.1.0.jar
2. Then it is to do a personalized address configuration, here to create the urlrewrite.xml, I put it in the Web-inf directory, the code is as follows:
<?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>^/u/([a-za-z0-9]*) $</ from> < totype= "Forward">/blog/tohome.do?xxx=$1</ to> </Rule> <Rule>//can also be configured a lot, with parameters or not with all can</Rule></Urlrewrite>
3. Next is to load our Urlrewrite.xml file in Web. XML, the code is as follows:
<!--URL Rewrite filter - <Filter> <Filter-name>Urlrewritefilter</Filter-name> <Filter-class>Org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</Filter-class> <Init-param> <Param-name>Confpath</Param-name> <Param-value>/web-inf/urlrewrite.xml</Param-value> </Init-param> </Filter> <filter-mapping> <Filter-name>Urlrewritefilter</Filter-name> <Url-pattern>/*</Url-pattern> </filter-mapping>
4. If it is without parameters, enter the alias access directly on the browser, and the background will automatically jump to the specified page.
4. If it is a parameter, the name of the domain address of the personality, here also gives a method, backstage received the request after processing, the code is as follows:
//Address bar Input alias processing@RequestMapping (value = {"/tohome"}, Method ={requestmethod.get}) PublicString Tohome (Member model, HttpServletRequest req, Modelmap modelmap) {//Query by aliasMap<string, object> maps =NewHashmap<string, object>(); Maps.put ("XXX", Model.getxxx ()); List<Object> list =Memberservice.selectall (maps); if(List! =NULL&& list.size () > 0) { //load data, jump return"Home/page"; } Else { return"404"; } }
5. Finally, we can enter on the browser: HTTP://WWW.XXX.COM/U/PP to see the effect.
Java development: Share a personalized visit using Urlrewrite to achieve URLs