Why Search Engine Optimization?

 

You have a web site. How do you get your web site noticed by your potential customers?  When people search key words in Google, Bing or Yahoo, it is vital for your web site to rank high in search engines to attract visitors and turn visitors into leads and sales.

One vital SEO component is friendly URL.  Unfortunately the default Seam URL is not SEO friendly.

 

Here is one example of Seam URL:

http://localhost:8080/seam-bay/search.seam?categoryId=11

Here is an example of SEO friendly URL:

http://localhost:8080/seam-bay/category/books

 

What is Tuckey URL Rewrite?

 

UrlRewriteFilter is a Java Web Filter for any J2EE compliant web application server, which allows you to rewrite URLs before they get to your code.  Developers can specify the inbound and outbound rules in the urlwrite.xml file.

In the following example, requests for /world/usa/nyc will be transparently forwarded to /world.jsp

<rule>
        <name>World Rule</name>
        <from>^/world/([a-z]+)/([a-z]+)$</from>
        <to>/world.jsp?country=$1&amp;city=$2</to>
    </rule> 

>

 

Configure Seam Application to use Tuckey URL Rewrite

 

It is actually very easy. Just add the following lines to your web.xml file. Please look the Seam Bay application in Seam examples folder.

<!-- URL Rewrite Filter -->

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

    </filter-mapping>

 

How to create SEO friendly links?

 

Seam bay is already configured to use UrlRewrite filter. So I made some modification to the home.xhtml. I used <h:outputLink> to expose category as SEO friendly links. 

 

  <ui:repeat id="categories" value="#{categories}" var="cat">      

<h:outputLink value="#{facesContext.externalContext.requestContextPath}/category/#{cat.name}">

         #{cat.name}

</h:outputLink>

</ui:repeat>

 

Seam Bay.jpg

 

 

How to process SEO friendly links?

 

Step1: add an inbound rule rewrite rule in the urlrewrite.xml.

 

<rule>

     <from>^/category/([A-Za-z0-9]*)$</from>

     <to last="true">/search.seam?categoryName=$1</to>

   </rule>

Urlrewrite will then rewrite http://localhost:8080/seam-bay/category/Books to: http://localhost:8080/seam-bay/search.seam?categoryName=Books

 

Step2:  modify pages.xml to handle URL parameters

<page view-id="/search.xhtml" >

  <param name="categoryName" value="#{auctionSearch.bookMarkCategoryName}"/>

   </page>

 

Step 3:   modify AuctionSearch.java

 

private String bookMarkCategoryName;

public String getBookMarkCategoryName()

   {

      return bookMarkCategoryName;

   }

   public void setBookMarkCategoryName(String categoryName)

   {

      List<Category> children = entityManager.createQuery(

            "from Category c where UPPER(c.name) = :name")

            .setParameter("name", categoryName.toUpperCase() )

            .getResultList();

        if(children.size()>0)

            {  

            this.searchCategory=children.get(0);

            }

            queryAuctions(); 

   }

 

You are done.