MilesWeb
MilesWeb Hosting Forum

Please login or register.

Login with username, password and session length

 

News:

SMF - Just Installed!


Author Topic: How to set redirection for non www to www URL in tomcat using UrlRewriteFilter  (Read 5304 times)

0 Members and 1 Guest are viewing this topic.

Offline Manish

  • Newbie
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Hi All,

You can set redirection for non-www URL to www URL in tomcat using UrlRewriteFilter. Below are the steps to set redirection:

1) Download UrlRewriteFilter to WEB-INF/lib directory of your website.

2) Go to WEB-INF/web.xml and add below code (near the top above any servlet mappings):


<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>



3) Create file urlrewrite.xml in WEB-INF and add below code:


<urlrewrite>
<rule>
              <name>Domain Name Check for example.com</name>
                <condition name="host" operator="equal">^example.com</condition>
               <from>^(.*)$</from>
               <to type="redirect">http://www.example.com$1</to>
      </rule>
</urlrewrite>



Note: Replace example.com with original domain name.

4) Restart tomcat service on the server.

That's all. Your website should now redirect from non www URL to www URL.

MilesWeb Hosting Forum