Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > tomcat redirect localhost

Reply
Thread Tools

tomcat redirect localhost

 
 
csteacy
Guest
Posts: n/a
 
      09-12-2006
Hello,
I'm working with an application that uses apache tomcat to serve the
website. I've installed the application and tomcat on a Windows 2003
server and everything is working fine. I do not have Apache or IIS
installed on the server. What I was trying to figure out is how to
make events.mydomain.xxx redirect to the localhost/myapp but without
the localhost part. For instance I want http://events.mydomain.xxx/ to
go to http://events.mydomain.xxx/myapp.

Any ideas how I might do this with apache tomcat would be very helpful
and appreciated. Thank you in advance.

 
Reply With Quote
 
 
 
 
Manish Pandit
Guest
Posts: n/a
 
      09-12-2006
Hi,

Based on what I understood, are you using absolute URLs in your app
instead of relative? If you were refering to root as / instead of
your.app.domain/ the app would have worked fine regardless of the
domain it is installed on. Is this the case?

-cheers,
Manish

 
Reply With Quote
 
 
 
 
csteacy
Guest
Posts: n/a
 
      09-12-2006
Manish Pandit wrote:
> Hi,
>
> Based on what I understood, are you using absolute URLs in your app
> instead of relative? If you were refering to root as / instead of
> your.app.domain/ the app would have worked fine regardless of the
> domain it is installed on. Is this the case?
>
> -cheers,
> Manish


I'm a bit confused but I'll try to add more info. My app is installed
under the Tomcat root in the webapps/myapp/ directory. When I go to
http://localhost/myapp (on the server) it brings up the homepage. The
app is all preconfigured and I haven't touched tomcat to put in any
URLs or anything. I'm guessing upon install of the app that the folder
for it under tomcat root was created. I'm sorry I'm just not
knowledgable enough in this area. I hope that makes sense. Thanks
again for all the help.

Christy

 
Reply With Quote
 
bikemh
Guest
Posts: n/a
 
      09-12-2006
I think all you want is to write an index.jsp, and put that into
tomcat/webapps/ROOT

the JSP can use response.sendRedirect(string) from HttpServletResponse
(which is an implicit variable addressed in a JSP simply as-->
response)

csteacy wrote:

>
> I'm a bit confused but I'll try to add more info. My app is installed
> under the Tomcat root in the webapps/myapp/ directory. When I go to
> http://localhost/myapp (on the server) it brings up the homepage. The
> app is all preconfigured and I haven't touched tomcat to put in any
> URLs or anything. I'm guessing upon install of the app that the folder
> for it under tomcat root was created. I'm sorry I'm just not
> knowledgable enough in this area. I hope that makes sense. Thanks
> again for all the help.
>
> Christy


 
Reply With Quote
 
Manish Pandit
Guest
Posts: n/a
 
      09-12-2006
If you want your application to show up as default tomcat app
(localhost instead of locahost/yourapp) , then go to the tomcat's
webapps folder, remove the contents of /ROOT, put your application in
there and give it a try after restarting tomcat. Again - I am not sure
if this is what you want.

-cheers,
Manish

csteacy wrote:
> Manish Pandit wrote:
> > Hi,
> >
> > Based on what I understood, are you using absolute URLs in your app
> > instead of relative? If you were refering to root as / instead of
> > your.app.domain/ the app would have worked fine regardless of the
> > domain it is installed on. Is this the case?
> >
> > -cheers,
> > Manish

>
> I'm a bit confused but I'll try to add more info. My app is installed
> under the Tomcat root in the webapps/myapp/ directory. When I go to
> http://localhost/myapp (on the server) it brings up the homepage. The
> app is all preconfigured and I haven't touched tomcat to put in any
> URLs or anything. I'm guessing upon install of the app that the folder
> for it under tomcat root was created. I'm sorry I'm just not
> knowledgable enough in this area. I hope that makes sense. Thanks
> again for all the help.
>
> Christy


 
Reply With Quote
 
bikemh
Guest
Posts: n/a
 
      09-12-2006

Manish Pandit wrote:
> If you want your application to show up as default tomcat app
> (localhost instead of locahost/yourapp) , then go to the tomcat's
> webapps folder, remove the contents of /ROOT, put your application in
> there and give it a try after restarting tomcat. Again - I am not sure
> if this is what you want.


if she wanted to go that route, you could instead just edit server.xml
so that

<Host name="events.mydomain.xxx" appBase="">

<Context path="/" docBase="tomcat_home/webapps/myapp" />

</Host>

and thus redefine what is normally the ROOT webapp

 
Reply With Quote
 
csteacy
Guest
Posts: n/a
 
      09-19-2006
> if she wanted to go that route, you could instead just edit server.xml
> so that
>
> <Host name="events.mydomain.xxx" appBase="">
>
> <Context path="/" docBase="tomcat_home/webapps/myapp" />
>
> </Host>
>
> and thus redefine what is normally the ROOT webapp


I wanted to post back that this did work after a couple of trial and
error situations and remembering that I was working locally and not
publically yet so I had to use .local in the URL when testing instead
of the .com or .edu. Thank you again for all the advice and help.

-Christy

 
Reply With Quote
 
scottdnerd scottdnerd is offline
Junior Member
Join Date: May 2010
Posts: 1
 
      05-03-2010
In Tomcat 6 I used a relative path to make this work:

<Context path="/" docBase="myWebapp"/>
 
Reply With Quote
 
sam55 sam55 is offline
Junior Member
Join Date: Dec 2010
Posts: 1
 
      12-14-2010
In order to do this the SEO-friendly and correct way so that Google does not identify you as having two different domains -- you need to use a specific HTTP 301 Redirect Code.

The only tricky way I found to do this in Tomcat was to use a Custom 404 Page implementation.

Add a new host entry in $CATALINA_BASE/server.xml as follows
Code:
            <Host name="newhost" debug="0" appBase="appbase" unpackWARs="true">
                <Context path="" docBase="docBase" debug="0">
                </Context>
            </Host>
Create a file $CATALINA_BASE/appbase/docBase/WEB-INF/web.xml as follows
Code:
<web-app>
    <error-page>
        <error-code>404</error-code>
        <location>/404.jsp</location>
    </error-page>
</web-app>
Create a file $CATALINA_BASE/appbase/docBase/404.jsp as follows
Code:
<%
response.setStatus(301);
response.setHeader( "Location", "newbaseURL" + (String)request.getAttribute("javax.servlet.forward.request_uri") );
response.setHeader( "Connection", "close" );
%>
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Limit Ring server to localhost only. RingFinger.new('localhost')apparently doesn't work koicat Ruby 0 07-02-2010 08:01 PM
change from "//localhost:numbers/" to just "//localhost/"? =?Utf-8?B?S2VuTGVl?= ASP .Net 5 02-12-2006 05:14 AM
Localhost isn't localhost EdwardH Java 20 10-01-2005 12:08 AM
Can I Reset the Root from localhost/myproject/ to localhost/ Alex ASP .Net 4 02-08-2005 01:45 PM
HttpModule -- how to intercept urls like http://localhost/abc/def or http://localhost/abc/def/ where abc, def are non virtual dir Jiong Feng ASP .Net 0 11-19-2003 05:29 AM



Advertisments