tomcat redirect localhost

Discussion in 'Java' started by csteacy, Sep 12, 2006.

  1. csteacy

    csteacy Guest

    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.
     
    csteacy, Sep 12, 2006
    #1
    1. Advertising

  2. 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
     
    Manish Pandit, Sep 12, 2006
    #2
    1. Advertising

  3. csteacy

    csteacy Guest

    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
     
    csteacy, Sep 12, 2006
    #3
  4. csteacy

    bikemh Guest

    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
     
    bikemh, Sep 12, 2006
    #4
  5. 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
     
    Manish Pandit, Sep 12, 2006
    #5
  6. csteacy

    bikemh Guest

    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
     
    bikemh, Sep 12, 2006
    #6
  7. csteacy

    csteacy Guest

    > 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
     
    csteacy, Sep 19, 2006
    #7
  8. csteacy

    scottdnerd

    Joined:
    May 3, 2010
    Messages:
    1
    Close but not quite

    In Tomcat 6 I used a relative path to make this work:

    <Context path="/" docBase="myWebapp"/>
     
    scottdnerd, May 3, 2010
    #8
  9. csteacy

    sam55

    Joined:
    Dec 14, 2010
    Messages:
    1
    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" );
    %> 
    
     
    sam55, Dec 14, 2010
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jiong Feng
    Replies:
    0
    Views:
    877
    Jiong Feng
    Nov 19, 2003
  2. Alex
    Replies:
    4
    Views:
    587
    Hasani Blackwell
    Feb 8, 2005
  3. =?Utf-8?B?S2VuTGVl?=
    Replies:
    5
    Views:
    2,733
  4. EdwardH

    Localhost isn't localhost

    EdwardH, Sep 29, 2005, in forum: Java
    Replies:
    20
    Views:
    6,436
    Roedy Green
    Oct 1, 2005
  5. koicat
    Replies:
    0
    Views:
    243
    koicat
    Jul 2, 2010
Loading...

Share This Page