Anyone who actively markets their business online knows the importance of search engine optimization. The right optimization strategy can drastically improve awareness and revenues; a strategy that can fall apart if you restructure your web site. That was the risk DLI.tools faced when we ‘moved’ our Collaborative Document Management solution, Docova, from www.dlitools.com to its own domain: www.docova.com. The risk: Losing our optimized results we had worked so hard to build. Based on SEO best practices, we knew that we had to implement a 301 redirection plan for all the affected pages, one that proved to be not so straight forward on our Domino R7 environment. Note: Domino R8 does provide rules for proper 301 redirects, so this workaround is applicable to R7 and below.
301 Redirect Requirements
In order to create a 301 redirect in Domino R7, you need to respond to clients with the HTTP status code of 301 to tell the browser the requested resource has moved permanently. Domino by default allows you to customize HTTP header fields but it generates the HTTP status codes itself preventing you from customizing these. Therefore, a workaround process is required to re-turn the status code of 301 and to populate the HTTP header field called "Location" with the URL that you would like to redirect to.
One way to accomplish this in Domino R7 is to use a Java Servlet. Servlets are able to respond with their own HTTP response codes, so they are a good candidate for this. Note that any envi-ronment that permits you to customize the response code and HTTP header can be used.
To handle a redirect you will want to be able to respond to the GET requests from the browser with the status of 301 and the also provide the location to redirect the user to. The browser han-dles the actual redirection based on the response and http header field (location).
Appropriate Java Classes
The class javax.servlet.http.HttpServlet http://java.sun.com/products/servlet/2.1/api/javax.servlet.http.HttpServlet.html has methods for handling each of the http request types, the one we are concerned with is GET, doGet allows you to respond to those client requests through a servlet. This method has two parameters passed in the javax.servlet.http.HttpServletRequest and javax.servlet.http.HttpServletResponse. These classes allow you to process the client request and compute a response, to do this create a new java class that extends this class (HttpServlet) in order to respond to the client requests using your custom servlet response.
A typical response would be....
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
public class SAMPLE1 extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)
{
try
{
//return the html below to the browser, Status OK
response.setContentType("text/html");
response.setStatus(200);
response.getWriter().println("
}
catch (Exception e)
{
response.getWriter().println(e);
}
}
}
A 301 redirect response would look like...
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
public class SAMPLE2 extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)
{
try
{
//tell the browser to redirect the client to the new permanent URL below, 301 Redirect
response.setContentType("text/html");
response.setStatus(301);
//the browser will redirect to the location specified in this header field
response.setHeader("Location","http://www.docova.com");
}
catch (Exception e)
{
response.getWriter().println(e);
}
}
} Add / Read Comments (0)
Jeff Primeau May 2nd, 2008 01:16:27 PM

