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>
网友留言: