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>
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: windows重启服务器的方法是什么