Tomcat by default the domain name without www will not jump to the domain name with www, and can not be configured as Apache. htaccess to achieve. If you want to redirect the domain name without "www" to the domain name with "www", and do not want to write code, you can use Urlrewritefilter to implement it.
1. Introduction
Urlrewritefilter is a web filter for overwriting URLs, similar to Apache's mod_rewrite. Applies to any Web application server (such as tomcat,jboss,jetty,resin,orion, etc.). Its typical application is to static dynamic URLs, so that search engine crawler crawl your dynamic Web pages.
2. Download
Download Urlrewritefilter
wget Http://urlrewritefilter.googlecode.com/files/urlrewritefilter-4.0.3.jar
And put it under Tomcat's web-inf/lib.
3. Configure Tomcat
Edit Web-inf/web.xml Join before other 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. Add a Jump Rule
Create a new Urlrewite.xml file under Web-inf and join the jump rule
<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>
Reference articles
http://nematodes.org/martin/2010/02/04/301-permanent-redirect-with-tomcat-howto/
http://tuckey.org/urlrewrite/
Tomcat Configuration 301 redirection (urlrewrite URL rewrite)