Urlwritefilter隆重登场
official website:
http://urlrewritefilter.googlecode.com
my web.xml is as follow, I think the order of the configuration is also very important.
<filter>
<filter-name>struts-cleanup</filter-name>
<filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
</filter>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
<init-param>
<param-name>logLevel</param-name>
<param-value>DEBUG</param-value>
</init-param>
<init-param>
<param-name>statusPath</param-name>
<param-value>/status</param-value>
</init-param>
</filter>
<filter>
<filter-name>StoreFilter</filter-name>
<filter-class>com.xxxx.web.filter.StoreFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts-cleanup</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>StoreFilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>StoreFilter</filter-name>
<url-pattern>*.html</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>*.html</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/status</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
And I put urlrewrite.xml in my WEB-INF, I think the order of the rules are also important.
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.2//EN"
"http://tuckey.org/res/dtds/urlrewrite3.2.dtd">
<urlrewrite>
<rule>
<name>catalog list page with page navigate</name>
<from>/catalog/cid_([0-9]+)/p_([0-9]*)/po_([0-9]*)/o_([^/]*)/(.*)\.html</from>
<to>/catalog.do?cid=$1&p=$2&po=$3&o=$4</to>
</rule>
<rule>
<name>catalog list page</name>
<from>/catalog/cid_([0-9]+)/(.*)\.html</from>
<to>/catalog.do?cid=$1</to>
</rule>
<rule>
<name>product detail from sku</name>
<from>/product_detail/itemid_([0-9A-Za-z]+)/attributeIndex_([0-9]*)/(.*)\.html</from>
<to>/product/detail.do?itemId=$1&attributeIndex=$2</to>
</rule>
<rule>
<name>product detail</name>
<from>/product_detail/itemid_([0-9A-Za-z]+)/(.*)\.html</from>
<to>/product/detail.do?itemId=$1</to>
</rule>
<rule>
<name>product other image</name>
<from>/product_otherimage/itemid_([0-9A-Za-z]+)/(.*)\.html</from>
<to>/product/otherImage.do?itemId=$1</to>
</rule>
<rule>
<name>product sku</name>
<from>/product_sku/itemid_([0-9A-Za-z]+)/(.*)\.html</from>
<to>/product/sku.do?itemId=$1</to>
</rule>
<outbound-rule>
<name>catalog list page with page navigate</name>
<from>/catalog\.do\?cid=([0-9]+)&p=([0-9]+)&po=([0-9]+)&o=([^/]*)</from>
<to>/catalog/cid_$1/p_$2/po_$3/o_$4.html</to>
</outbound-rule>
<outbound-rule>
<name>catalog list page with page navigate</name>
<from>/catalog\.do\?cid=([0-9]+)</from>
<to>/catalog/cid_$1.html</to>
</outbound-rule>
<outbound-rule>
<from>/old/url/scheme/page.jsp</from>
<to>/tidy/page</to>
</outbound-rule>
</urlrewrite>
A test class for regex, URLRewriteTest2.java:
package com.xxxx.utils;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class URLRewriteTest2
{
public static void main(String[] args)
{
String from = "/catalog/cid_([0-9]+)/(.)*\\.html";
String to = "/catalog.do?cid=$1";
System.out.println();
System.out.println(getResult(from, to, "http://localhost:8080/lillypulitzer/catalog/cid_385313/Women.html"));
System.out.println(getResult(from, to, "http://localhost:8080/lillypulitzer/catalog/cid_385315/Women/New%20Arrivals.html"));
System.out.println(getResult(from, to, "http://localhost:8080/lillypulitzer/catalog/cid_385315/Women/New%20Arrivals.htm"));
System.out.println(getResult(from, to, "http://localhost:8080/lillypulitzer/catalog/cid_385315/Women/New%20Arrivalshtml"));
System.out.println();
from = "/catalog/cid_([0-9]+)/p_([0-9]+)/po_([0-9]+)/o_([^/]*)/(.)*\\.html";
to = "/catalog.do?cid=$1&p=$2&po=$3&o=$4";
System.out.println(getResult(from,to,"http://localhost:8080/lillypulitzer/catalog/cid_385315/p_2/po_10/o_/Women.html"));
System.out.println(getResult(from,to,"http://localhost:8080/lillypulitzer/catalog/cid_385315/p_2/po_10/o_/Women|New%20Arrivals.html"));
System.out.println(getResult(from,to,"http://localhost:8080/lillypulitzer/catalog/cid_628185/p_1/po_10/o_Product%20Price::asc/Women.html"));
System.out.println();
from = "/product_detail/itemid_([0-9A-Za-z]+)/attributeIndex_([0-9]*)/(.)*\\.html";
to = "/product/detail.do?itemId=$1&attributeIndex=$2";
System.out.println(getResult(from,to,"http://localhost:8080/lillypulitzer/product_detail/itemid_82750/attributeIndex_0/Adalie%20Wrap%20Dress%20Printed.html"));
System.out.println();
from = "/product_detail/itemid_([0-9A-Za-z]+)/(.)*\\.html";
to = "/product/detail.do?itemId=$1";
System.out.println(getResult(from,to,"http://localhost:8080/lillypulitzer/product_detail/itemid_343/Clothes.html"));
System.out.println();
from = "/product_otherimage/itemid_([0-9A-Za-z]+)/(.)*\\.html";
to = "/product/otherImage.do?itemId=$1";
System.out.println(getResult(from,to,"http://localhost:8080/lillypulitzer/product_otherimage/itemid_343/Clothes.html"));
System.out.println();
from = "/product_sku/itemid_([0-9A-Za-z]+)/(.)*\\.html";
to = "/product/sku.do?itemId=$1";
System.out.println(getResult(from,to,"http://localhost:8080/lillypulitzer/product_sku/itemid_343/Clothes.html"));
System.out.println();
from = "/catalog\\.do\\?cid=([0-9]+)&p=([0-9]*)&po=([0-9]*)&o=([^/]*)&catalogName=(.*)";
to = "/catalog/cid_$1/p_$2/po_$3/o_$4/$5\\.html";
System.out.println(getResult(from,to,"http://localhost:8080/lillypulitzer/catalog.do?cid=34343&p=1&po=1&o=teasdfasdf&catalogName=Womain|New%20Attrive"));
}
private static String getResult(String from, String to, String request)
{
Pattern pattern = Pattern.compile(from);
Matcher matcher = pattern.matcher(request);
String result = matcher.replaceAll(to);
return result;
}
}
for outpound url, you can have a url.jsp for test:
catalog list<br />
<%= response.encodeURL("/catalog.do?cid=343434") %> <br />
<%= response.encodeURL("/old/url/scheme/page.jsp") %> <br />
<%= response.encodeURL("/catalog.do?cid=343434&p=1&po=10&o=Women|NewArravel") %> <br />
<br/>
you can get the answer:
catalog list
/catalog/cid_343434.html
/tidy/page
/catalog/cid_343434/p_1/po_10/o_Women|NewArravel.html
So, you can use your orignal URL if you delete the configuration files.
you can watch the status via this URL:
http://localhost:8080/lillypulitzer/status
official website:
http://urlrewritefilter.googlecode.com
my web.xml is as follow, I think the order of the configuration is also very important.
<filter>
<filter-name>struts-cleanup</filter-name>
<filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
</filter>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
<init-param>
<param-name>logLevel</param-name>
<param-value>DEBUG</param-value>
</init-param>
<init-param>
<param-name>statusPath</param-name>
<param-value>/status</param-value>
</init-param>
</filter>
<filter>
<filter-name>StoreFilter</filter-name>
<filter-class>com.xxxx.web.filter.StoreFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts-cleanup</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>StoreFilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>StoreFilter</filter-name>
<url-pattern>*.html</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>*.html</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/status</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
And I put urlrewrite.xml in my WEB-INF, I think the order of the rules are also important.
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.2//EN"
"http://tuckey.org/res/dtds/urlrewrite3.2.dtd">
<urlrewrite>
<rule>
<name>catalog list page with page navigate</name>
<from>/catalog/cid_([0-9]+)/p_([0-9]*)/po_([0-9]*)/o_([^/]*)/(.*)\.html</from>
<to>/catalog.do?cid=$1&p=$2&po=$3&o=$4</to>
</rule>
<rule>
<name>catalog list page</name>
<from>/catalog/cid_([0-9]+)/(.*)\.html</from>
<to>/catalog.do?cid=$1</to>
</rule>
<rule>
<name>product detail from sku</name>
<from>/product_detail/itemid_([0-9A-Za-z]+)/attributeIndex_([0-9]*)/(.*)\.html</from>
<to>/product/detail.do?itemId=$1&attributeIndex=$2</to>
</rule>
<rule>
<name>product detail</name>
<from>/product_detail/itemid_([0-9A-Za-z]+)/(.*)\.html</from>
<to>/product/detail.do?itemId=$1</to>
</rule>
<rule>
<name>product other image</name>
<from>/product_otherimage/itemid_([0-9A-Za-z]+)/(.*)\.html</from>
<to>/product/otherImage.do?itemId=$1</to>
</rule>
<rule>
<name>product sku</name>
<from>/product_sku/itemid_([0-9A-Za-z]+)/(.*)\.html</from>
<to>/product/sku.do?itemId=$1</to>
</rule>
<outbound-rule>
<name>catalog list page with page navigate</name>
<from>/catalog\.do\?cid=([0-9]+)&p=([0-9]+)&po=([0-9]+)&o=([^/]*)</from>
<to>/catalog/cid_$1/p_$2/po_$3/o_$4.html</to>
</outbound-rule>
<outbound-rule>
<name>catalog list page with page navigate</name>
<from>/catalog\.do\?cid=([0-9]+)</from>
<to>/catalog/cid_$1.html</to>
</outbound-rule>
<outbound-rule>
<from>/old/url/scheme/page.jsp</from>
<to>/tidy/page</to>
</outbound-rule>
</urlrewrite>
A test class for regex, URLRewriteTest2.java:
package com.xxxx.utils;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class URLRewriteTest2
{
public static void main(String[] args)
{
String from = "/catalog/cid_([0-9]+)/(.)*\\.html";
String to = "/catalog.do?cid=$1";
System.out.println();
System.out.println(getResult(from, to, "http://localhost:8080/lillypulitzer/catalog/cid_385313/Women.html"));
System.out.println(getResult(from, to, "http://localhost:8080/lillypulitzer/catalog/cid_385315/Women/New%20Arrivals.html"));
System.out.println(getResult(from, to, "http://localhost:8080/lillypulitzer/catalog/cid_385315/Women/New%20Arrivals.htm"));
System.out.println(getResult(from, to, "http://localhost:8080/lillypulitzer/catalog/cid_385315/Women/New%20Arrivalshtml"));
System.out.println();
from = "/catalog/cid_([0-9]+)/p_([0-9]+)/po_([0-9]+)/o_([^/]*)/(.)*\\.html";
to = "/catalog.do?cid=$1&p=$2&po=$3&o=$4";
System.out.println(getResult(from,to,"http://localhost:8080/lillypulitzer/catalog/cid_385315/p_2/po_10/o_/Women.html"));
System.out.println(getResult(from,to,"http://localhost:8080/lillypulitzer/catalog/cid_385315/p_2/po_10/o_/Women|New%20Arrivals.html"));
System.out.println(getResult(from,to,"http://localhost:8080/lillypulitzer/catalog/cid_628185/p_1/po_10/o_Product%20Price::asc/Women.html"));
System.out.println();
from = "/product_detail/itemid_([0-9A-Za-z]+)/attributeIndex_([0-9]*)/(.)*\\.html";
to = "/product/detail.do?itemId=$1&attributeIndex=$2";
System.out.println(getResult(from,to,"http://localhost:8080/lillypulitzer/product_detail/itemid_82750/attributeIndex_0/Adalie%20Wrap%20Dress%20Printed.html"));
System.out.println();
from = "/product_detail/itemid_([0-9A-Za-z]+)/(.)*\\.html";
to = "/product/detail.do?itemId=$1";
System.out.println(getResult(from,to,"http://localhost:8080/lillypulitzer/product_detail/itemid_343/Clothes.html"));
System.out.println();
from = "/product_otherimage/itemid_([0-9A-Za-z]+)/(.)*\\.html";
to = "/product/otherImage.do?itemId=$1";
System.out.println(getResult(from,to,"http://localhost:8080/lillypulitzer/product_otherimage/itemid_343/Clothes.html"));
System.out.println();
from = "/product_sku/itemid_([0-9A-Za-z]+)/(.)*\\.html";
to = "/product/sku.do?itemId=$1";
System.out.println(getResult(from,to,"http://localhost:8080/lillypulitzer/product_sku/itemid_343/Clothes.html"));
System.out.println();
from = "/catalog\\.do\\?cid=([0-9]+)&p=([0-9]*)&po=([0-9]*)&o=([^/]*)&catalogName=(.*)";
to = "/catalog/cid_$1/p_$2/po_$3/o_$4/$5\\.html";
System.out.println(getResult(from,to,"http://localhost:8080/lillypulitzer/catalog.do?cid=34343&p=1&po=1&o=teasdfasdf&catalogName=Womain|New%20Attrive"));
}
private static String getResult(String from, String to, String request)
{
Pattern pattern = Pattern.compile(from);
Matcher matcher = pattern.matcher(request);
String result = matcher.replaceAll(to);
return result;
}
}
for outpound url, you can have a url.jsp for test:
catalog list<br />
<%= response.encodeURL("/catalog.do?cid=343434") %> <br />
<%= response.encodeURL("/old/url/scheme/page.jsp") %> <br />
<%= response.encodeURL("/catalog.do?cid=343434&p=1&po=10&o=Women|NewArravel") %> <br />
<br/>
you can get the answer:
catalog list
/catalog/cid_343434.html
/tidy/page
/catalog/cid_343434/p_1/po_10/o_Women|NewArravel.html
So, you can use your orignal URL if you delete the configuration files.
you can watch the status via this URL:
http://localhost:8080/lillypulitzer/status