Can I redirect from a non existing url?

127 views
Skip to first unread message

Xavi

unread,
Nov 6, 2007, 10:22:18 AM11/6/07
to UrlRewrite
Hi,

I would like to type

http://localhost:8840/app/about

(note than "about" does not exist neither as a directory or file.)

and then being redirected to

http://localhost:8840/app/index.jsp?pageName=about

Can anyone tell me the rule, if exist, for that?

thanks

Mike Dillon

unread,
Nov 6, 2007, 10:50:41 AM11/6/07
to urlre...@googlegroups.com
begin Xavi quotation:

Assuming /app is your context path:

<rule>
<from>^/about$</from>
<to type="redirect">/index.php?pageName=about</to>
</rule>

If you want something more general, you'd have to describe what the part
after /about can have in it other than "about".

Note, for this to work, you have to set up the filter mapping to cover
/about. If you're mapping UrlRewriteFilter to "/*", it should work.

-md

Xavi

unread,
Nov 8, 2007, 4:45:53 AM11/8/07
to UrlRewrite

hmm. I've got a Forbidden (403)You have requested data that the server
has decided not to provide to you. Your request was understood and
denied.

from that URL http://localhost:8840/ccp/cms/html/about I want
theurlrewrite to redirect to http://localhost:8840/ccp/cms/html/index.jsp

my web.xml filter mapping bit is:

<filter-mapping>
<filter-name>FriendlyURLServlet</filter-name>
<url-pattern>/ccp/cms</url-pattern>
</filter-mapping>

where /ccp/cms is my context path

and my rule:
<rule>
<from>^/about$</from>
<to>%{context-path}/html/index.jsp</to>
</rule>

any idea of what is wrong?

Mike Dillon

unread,
Nov 8, 2007, 10:14:31 AM11/8/07
to urlre...@googlegroups.com
begin Xavi quotation:

> hmm. I've got a Forbidden (403)You have requested data that the server
> has decided not to provide to you. Your request was understood and
> denied.

I'm not sure why you've gotten a 403, but I don't think that
UrlRewriteFilter is being hit.

> from that URL http://localhost:8840/ccp/cms/html/about I want
> theurlrewrite to redirect to http://localhost:8840/ccp/cms/html/index.jsp
>
> my web.xml filter mapping bit is:
>
> <filter-mapping>
> <filter-name>FriendlyURLServlet</filter-name>
> <url-pattern>/ccp/cms</url-pattern>
> </filter-mapping>
>
> where /ccp/cms is my context path
>
> and my rule:
> <rule>
> <from>^/about$</from>
> <to>%{context-path}/html/index.jsp</to>
> </rule>
>
> any idea of what is wrong?

If your context path is really "/ccp/cms", then need something like this
in web XML:

<filter-mapping>
<filter-name>FriendlyURLServlet</filter-name>
<url-pattern>/html/*</url-pattern>
</filter-mapping>

And this in urlrewrite.xml:

<rule>
<from>^/html/about$</from>
<to type="redirect">/html/index.jsp?pageName=about</to>
</rule>

Nothing in web.xml or urlrewrite.xml generally needs to know what your
context path is since they default to doing everything relative to the
context path.

Note: if you really want to "redirect" (in which case the user will see
"index.jsp" in their browser), you need type="redirect". Otherwise, what
you're doing is called "forwarding" and you probably need last="true" on
the <to> element. If you want names other than "about" to work, you'll
have to tell us what those possible names look like so that the <from>
pattern can be changed to accomodate other names.

-md

Xavi

unread,
Nov 12, 2007, 5:08:08 AM11/12/07
to UrlRewrite
THanks for your help. I've just found out the 404 is because the web
framework I am using is capturing the requests through a pipeline of
servlets. So I will need to check this servlets to avoid getting the
404.

thank you very mutch for your help.


On 8 Nov, 16:14, Mike Dillon <m...@embody.org> wrote:
> begin Xavi quotation:
>
> > hmm. I've got a Forbidden (403)You have requested data that the server
> > has decided not to provide to you. Your request was understood and
> > denied.
>
> I'm not sure why you've gotten a 403, but I don't think that
> UrlRewriteFilter is being hit.
>
>
>
> > from that URLhttp://localhost:8840/ccp/cms/html/aboutI want

> > theurlrewrite to redirect tohttp://localhost:8840/ccp/cms/html/index.jsp

Reply all
Reply to author
Forward
0 new messages