You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by "Zhao, David" <Da...@ACTIVX.com> on 2006/07/06 22:53:30 UTC

RE: URL rewriting

Thanks very much Jurgen, redirecting using index.jsp works great!

David

-----Original Message-----
From: Jürgen Hoffmann [mailto:jh@byteaction.de] 
Sent: Saturday, June 24, 2006 4:03 PM
To: Turbine Users List
Subject: Re: URL rewriting

Hi David, 

ok here is how I am tackling this. It might not be eprfect but works for me.

If I am running Tomcat on Port 80, I am doing the following:

- edit $TOMCAT_HOME/webapps/root/WEB-INF/web.xml and comment out

    <servlet>
        <servlet-name>org.apache.jsp.index_jsp</servlet-name>
        <servlet-class>org.apache.jsp.index_jsp</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>org.apache.jsp.index_jsp</servlet-name>
        <url-pattern>/index.jsp</url-pattern>
    </servlet-mapping>

- edit $TOMCAT_HOME/webapps/root/index.jsp to contain

<%
      response.sendRedirect(response.encodeRedirectURL("/MYAPP/app"));
%>

Then go and edit $TOMCAT_HOME/webapps/MYAPP/WEB-INF/web.xml to contain:

    <servlet-name>MYAPP</servlet-name>
    <servlet-class>org.apache.turbine.Turbine</servlet-class>
    <init-param>
      <param-name>applicationRoot</param-name>
      <param-value>webContext</param-value>
    </init-param>

    <init-param>
      <param-name>properties</param-name>
      <param-value>/WEB-INF/conf/TurbineResources.properties</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>MYAPP</servlet-name>
    <url-pattern>/app/*</url-pattern>
  </servlet-mapping>

then edit $TOMCAT_HOME/webapps/MYADD/index.jsp and put 

<%
      response.sendRedirect(response.encodeRedirectURL("/MYAPP/app"));
%>

in there too. 

No if someone acces your host using 

- http://yourhost.com/
- http://yourhost.com/MYAPP

he will be redirected onto http://yourhost.com/MYAPP/app and there then most 
likely to your Index.vm depending on how your Turbine Application is 
configured.

HTH

Juergen

Am Samstag, 24. Juni 2006 23:04 schrieb Zhao, David:
> Hi Tony and Jurgen,
>
> Thanks so much for your replies. We're running Tomcat
> 5.5/Turbine/Torque/Velocity here, and I was able to have tomcat configured
> to use port 80 instead of 8080. I have tried to edit the web.xml to make my
> application URL as: http://localhost/mywebapp, when setting:
>
>  <servlet-mapping>
>     <servlet-name>MYWEBAPP</servlet-name>
>     <url-pattern>/*</url-pattern>
>   </servlet-mapping>
>
> However, this will mess up Velocity's template link object, which couldn't
> find servle path (I think it still be looking under /SERVLET/WEBAPPS kind
> of path format, where in this case, servlet path is not there anymore).
>
> If I configure web.xml as the following:
>  <servlet-mapping>
>     <servlet-name>MYWEBAPP</servlet-name>
>     <url-pattern>/S/*</url-pattern>
>   </servlet-mapping>
> I'm able to access my application thru:
> http://localhost/S/mywebapp, which is not 100% satisfactory to me.
> BTW, how can I configure either Tomcat or Turbine to redirect the request
> to mywebapp.com to localhost/S/mywebapp? Thanks,
>
>
> David
>
> -----Original Message-----
> From: Jürgen Hoffmann [mailto:jh@byteaction.de]
> Sent: Sat 6/24/2006 1:08 PM
> To: Turbine Users List
> Subject: Re: URL rewriting
>
> Hi,
>
> Tony is right, albeit he only addresses the connector and rewrite issue. I
> agree that it is better to run  the servlet container in conjunction with
> apache webserver to serve static content.
>
> The problem I was addressing was that David seemed to be still using the
> Invoker Servlet (mywebapp/servlet/mywebapp) which adds just another layer
> to your Servlet, and is considered inseucure which is why it is commented
> out in newer tomcat releases. With my solution (copied from m.e.t.a.'s
> web.xml) there is no further need for the invoker servlet.
>
> Kind regards
>
> Juergen Hoffmann
>
> Am Samstag, 24. Juni 2006 15:47 schrieb Tony Oslund:
> > This is a bit of a cross post so you have my appologies...
> >
> > I am not sure if Jurgen's solution will work for the port number or not,
> > as I have not tried it for that.  I do know that the following will take
> > care of the 8080 portion of the problem however, as well as URL
> > re-writing.
> >
> > I will make the assumption that you are using Tomcat, JBoss, etc.  Are
> > you using them as stand alone servers, or are you using them in
> > conjuction with other servers, such as Apache, IIS, etc?  Apache and IIS
> > are much more efficient at serving up static content, and it takes the
> > burden for this off of your app server.  (For development, you can run
> > all of this on one box if you wish).
> >
> > Anyways you can use a "connector" (see the jakarta site), and relay any
> > requests coming into your Apache/IIS web server on port 80 to your
> > (Tomcat, JBoss) app server on 8080.  The other nice thing about doing
> > this is you can use Apache or IIS to setup name based, or IP based
> > virtual domains. This way you could refer to your app not only through
> > http://localhost.... but also through http://domain2...... or
> > http://domain3, etc.
> >
> > You can also setup matching url patterns with the connector as to what
> > requests are mapped to what app servers, etc.
> >
> > If you are running your app server in conjuction with Apache, there is
> > also mod_rewrite.  It is a plug in module for apache and allows URL
> > re-writing, before the request ever gets relayed to your app server
> >
> > If you are only running an app server (for your local development) you
> > could also make it easy on yourself and simply configure it to accept
> > requests on port 80.  You have to make sure that you do not have another
> > app or web server running that is already bound to that port on your
> > local box, but it does work.  However, this would present a bit of a
> > problem if you needed to run multiple app servers, etc.
> >
> > Tony
> >
> > ----- Original Message -----
> > From: "David Zhao" <wz...@gmail.com>
> > To: <tu...@jakarta.apache.org>
> > Sent: Friday, June 23, 2006 5:32 PM
> > Subject: URL rewriting
> >
> > > Hi there,
> > >
> > > How can I simplify my turbine application URL from:
> > >
> > > http://localhost:8080/mywebapp/servlet/mywebapp to:
> > >
> > > http://localhost/mywebapp?
> > >
> > > I've read URL rewriting HowTo on the turbine page, but need to further
> > > simply the URL structure.
> > > Thanks in advance!
> > >
> > > David
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: turbine-user-help@jakarta.apache.org
> >
> > !EXCUBATOR:1,449d429977961333248546!
>
> !EXCUBATOR:1,449da8e077962142010433!


-- 
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.394 / Virus Database: 268.9.4/375 - Release Date: 6/25/2006
 
  

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.394 / Virus Database: 268.9.9/382 - Release Date: 7/4/2006
 

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org