Redirect All page from one domain to another domain in tomcat

by Vinoth 2009-10-27 18:41:48

If you want to move all the pages in a particular folder to other domain
example
http://example.com/floder/filename?parameters to
http://newexample.com/floder/filename?parameters

Then to the following changes in your code
Step 1:
changes your web.xml :



<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name>Forum Moving </display-name>
<servlet>
<servlet-name>redirect.jsp </servlet-name>
<jsp-file>/redirect.jsp </jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>redirect.jsp </servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>

Here I'm redirecting all the request in that webapplication to "redirect.jsp"

Setp 2:
Create redirect.jsp file. Through this file we have to redirect the pages to the new domain


<%
String file = request.getRequestURI();
if (request.getQueryString() != null) {
file += '?' + request.getQueryString();
}
response.setStatus(301);
response.setHeader( "Location", "http://newdomain.com"+file );
response.setHeader( "Connection", "close" );
%>

Tagged in:

3682
like
0
dislike
0
mail
flag

You must LOGIN to add comments