Sunday, August 17, 2014

Perfofming SEO friendly site redirection on a java app server to another domain

Hello everybody,

Today I will analyze a very simple and successful way to redirect you old domain hosted in a java app server (Tomcat for our example) to your new domain so that search engines understand that the old domain does not exist anymore and has moved to a new location (SEO friendly : Search Engine Optimizations friendly). All you need to do is set up your old domain to respond with an http status code 301 that means "Moved Permanently" for any request.

First, in the root directory of your old domain create a jsp with the name redirect.jsp containing the following code :

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
response.setHeader( "Location", "");
response.setHeader( "Connection", "close" );

Replace "" with the url of your new domain.

Next add the following lines inside the root directory's web.xml (for Tomcat installations inside webapps/ROOT/WEB-INF/web.xml):


And we're done. You may notice that the servlet name is totally irrelevant, so you can change it to anything you like (change it in both lines to a new servlet name).

You can find me on fiverr for more personalized requests on any java app server configuration problem or java error that you encounter, with deliverance of less than a day (true!) and money back guarantee if not satisfied.

No comments:

Post a Comment