tomcat服務器做301重定向的方法:
1.借助UrlRewriteFilter軟件,下載命令:
wget http://urlrewritefilter.googlecode.com/files/urlrewritefilter-4.0.3.jar
2.解壓并放入到tomcat的WEB-INF/lib目錄下。
3.編輯WEB-INF/web.xml文件,在“servlet mapping”前加入以下代碼:
<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>
4.在WEB-INF下新建urlrewite.xml文件,加入跳轉規則,代碼如下:
<urlrewrite>
<rule>
<name>seo redirect</name>
<condition name="host" operator="notequal">^www.example.com</condition>
<condition name="host" operator="notequal">^localhost</condition>
<from>^/(.*)</from>
<to type="permanent-redirect" last="true">http://www.example.com/$1</to>
</rule>
</urlrewrite>