You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Hendy Irawan <he...@soluvas.com> on 2014/12/10 13:56:24 UTC
How to instruct RenderPageRequestHandler to redirect using 301
Permanent
I currently have a custom SEO-friendly RequestMapper with the following
snippet:
@Override
public final IRequestHandler mapRequest(Request request) {
try {
final String userAgent = ((HttpServletRequest)
request.getContainerRequest()).getHeader("User-Agent");
final RedirectPolicy redirectPolicy = userAgent != null &&
BotUtils.isBot(userAgent) ? RedirectPolicy.NEVER_REDIRECT :
RedirectPolicy.AUTO_REDIRECT;
final UrlInfo urlInfo = parseRequest(request);
// check if the URL is long enough and starts with the proper segments
if (urlInfo != null)
{
PageComponentInfo info = urlInfo.getPageComponentInfo();
Class<? extends IRequestablePage> pageClass = urlInfo.getPageClass();
PageParameters pageParameters = urlInfo.getPageParameters();
if (info == null)
{
// if there are is no page instance information
// then this is a simple bookmarkable URL
return processBookmarkable(pageClass, pageParameters, redirectPolicy);
}
else if (info.getPageInfo().getPageId() != null &&
info.getComponentInfo() == null)
{
// if there is page instance information in the URL but no component and
listener
// interface then this is a hybrid URL - we need to try to reuse
existing page
// instance
return processHybrid(info.getPageInfo(), pageClass, pageParameters,
null);
}
else if (info.getComponentInfo() != null)
{
// with both page instance and component+listener this is a listener
interface URL
return processListener(info, pageClass, pageParameters);
}
else if (info.getPageInfo().getPageId() == null)
{
return processBookmarkable(pageClass, pageParameters, redirectPolicy);
}
}
return null;
} catch (MapperRedirectException e) {
log.debug("Redirecting '{}' to canonical page: {}", request.getUrl(),
e.getPageProvider());
// return new RedirectRequestHandler(redirectUrl, 301);
return new RenderPageRequestHandler(e.getPageProvider(),
RedirectPolicy.ALWAYS_REDIRECT);
}
}
What it does is allow freeform root URI paths, e.g.
http://www.tuneeca.com/t-1113012 instead of the longer
http://www.tuneeca.com/product/t-1113012 .
Now, requests to http://www.tuneeca.com/product/t-1113012 are also handled
by the same RequestMapper and will be redirected to
http://www.tuneeca.com/t-1113012 .
However, currently it's using 302 temporary redirect. How to make it use 301
permanent redirect?
Thank you.
Hendy
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/How-to-instruct-RenderPageRequestHandler-to-redirect-using-301-Permanent-tp4668716.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: How to instruct RenderPageRequestHandler to redirect using 301
Permanent
Posted by Hendy Irawan <he...@soluvas.com>.
Awesome!!!
Thank so much Martin! And additional thanks for answering so quickly :))
Hendy
On Wed, Dec 10, 2014, 20:36 Martin Grigorov-4 [via Apache Wicket] <
ml-node+s1842946n4668721h49@n4.nabble.com> wrote:
> RequestCycle.get().urlFor(pageClass, parameters)
>
> Martin Grigorov
> Wicket Training and Consulting
> https://twitter.com/mtgrigorov
>
> On Wed, Dec 10, 2014 at 3:20 PM, Hendy Irawan <[hidden email]
> <http:///user/SendEmail.jtp?type=node&node=4668721&i=0>> wrote:
>
> > Thanks for prompt advice Martin, however please explain more... I
> commented
> > that code because I don't know how to construct the redirectUrl String
> from
> > a PageProvider, inside RequestMapper.mapRequest? (Or alternatively, from
> > PageClass + PageParameters)
> >
> > Hoping you can shed light on this.
> > Thanks in advance.
> >
> > Hendy
> >
> > On Wed, Dec 10, 2014, 20:12 Martin Grigorov-4 [via Apache Wicket] <
> > [hidden email] <http:///user/SendEmail.jtp?type=node&node=4668721&i=1>>
> wrote:
> >
> > > Hi,
> > >
> > > To do a "normal" redirect Wicket
> > > uses javax.servlet.http.HttpServletResponse#sendRedirect() and this
> sets
> > > 302 as a code.
> > > To have better control you should use RedirectRequestHandler, as in
> your
> > > commented out code.
> > >
> > > Martin Grigorov
> > > Wicket Training and Consulting
> > > https://twitter.com/mtgrigorov
> > >
> > > On Wed, Dec 10, 2014 at 2:56 PM, Hendy Irawan <[hidden email]
> > > <http:///user/SendEmail.jtp?type=node&node=4668717&i=0>> wrote:
> > >
> > > > I currently have a custom SEO-friendly RequestMapper with the
> following
> > > > snippet:
> > > >
> > > > @Override
> > > > public final IRequestHandler mapRequest(Request request) {
> > > > try {
> > > > final String userAgent = ((HttpServletRequest)
> > > > request.getContainerRequest()).getHeader("User-Agent");
> > > > final RedirectPolicy redirectPolicy = userAgent !=
> null
> > > &&
> > > > BotUtils.isBot(userAgent) ? RedirectPolicy.NEVER_REDIRECT :
> > > > RedirectPolicy.AUTO_REDIRECT;
> > > >
> > > > final UrlInfo urlInfo = parseRequest(request);
> > > >
> > > > // check if the URL is long enough and starts with
> the
> > > > proper segments
> > > > if (urlInfo != null)
> > > > {
> > > > PageComponentInfo info =
> > > > urlInfo.getPageComponentInfo();
> > > > Class<? extends IRequestablePage> pageClass
> =
> > > > urlInfo.getPageClass();
> > > > PageParameters pageParameters =
> > > > urlInfo.getPageParameters();
> > > >
> > > > if (info == null)
> > > > {
> > > > // if there are is no page instance
> > > > information
> > > > // then this is a simple
> bookmarkable
> > > URL
> > > > return
> processBookmarkable(pageClass,
> > > > pageParameters, redirectPolicy);
> > > > }
> > > > else if (info.getPageInfo().getPageId() !=
> null
> > > &&
> > > > info.getComponentInfo() == null)
> > > > {
> > > > // if there is page instance
> > information
> > > > in the URL but no component and
> > > > listener
> > > > // interface then this is a hybrid
> URL
> > -
> > > > we need to try to reuse
> > > > existing page
> > > > // instance
> > > > return
> > processHybrid(info.getPageInfo(),
> > > > pageClass, pageParameters,
> > > > null);
> > > > }
> > > > else if (info.getComponentInfo() != null)
> > > > {
> > > > // with both page instance and
> > > > component+listener this is a listener
> > > > interface URL
> > > > return processListener(info,
> pageClass,
> > > > pageParameters);
> > > > }
> > > > else if (info.getPageInfo().getPageId() ==
> > null)
> > > > {
> > > > return
> processBookmarkable(pageClass,
> > > > pageParameters, redirectPolicy);
> > > > }
> > > >
> > > > }
> > > > return null;
> > > > } catch (MapperRedirectException e) {
> > > > log.debug("Redirecting '{}' to canonical page: {}",
> > > > request.getUrl(),
> > > > e.getPageProvider());
> > > > // return new
> RedirectRequestHandler(redirectUrl,
> > > > 301);
> > > > return new
> > RenderPageRequestHandler(e.getPageProvider(),
> > > > RedirectPolicy.ALWAYS_REDIRECT);
> > > > }
> > > > }
> > > >
> > > > What it does is allow freeform root URI paths, e.g.
> > > > http://www.tuneeca.com/t-1113012 instead of the longer
> > > > http://www.tuneeca.com/product/t-1113012 .
> > > >
> > > > Now, requests to http://www.tuneeca.com/product/t-1113012 are also
> > > handled
> > > > by the same RequestMapper and will be redirected to
> > > > http://www.tuneeca.com/t-1113012 .
> > > >
> > > > However, currently it's using 302 temporary redirect. How to make it
> > use
> > > > 301
> > > > permanent redirect?
> > > >
> > > > Thank you.
> > > >
> > > > Hendy
> > > >
> > > >
> > > > --
> > > > View this message in context:
> > > >
> > >
> >
> http://apache-wicket.1842946.n4.nabble.com/How-to-instruct-RenderPageRequestHandler-to-redirect-using-301-Permanent-tp4668716.html
> > > > Sent from the Users forum mailing list archive at Nabble.com.
> > > >
> > > >
> ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: [hidden email]
> > > <http:///user/SendEmail.jtp?type=node&node=4668717&i=1>
> > > > For additional commands, e-mail: [hidden email]
> > > <http:///user/SendEmail.jtp?type=node&node=4668717&i=2>
> > > >
> > > >
> > >
> > >
> > > ------------------------------
> > > If you reply to this email, your message will be added to the
> discussion
> > > below:
> > >
> > >
> >
> http://apache-wicket.1842946.n4.nabble.com/How-to-instruct-RenderPageRequestHandler-to-redirect-using-301-Permanent-tp4668716p4668717.html
> > > To unsubscribe from How to instruct RenderPageRequestHandler to
> redirect
> > > using 301 Permanent, click here
> > > <
> >
> >
> > > .
> > > NAML
> > > <
> >
> http://apache-wicket.1842946.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml
>
> > >
> > >
> >
> >
> > --
> > View this message in context:
> >
> http://apache-wicket.1842946.n4.nabble.com/How-to-instruct-RenderPageRequestHandler-to-redirect-using-301-Permanent-tp4668716p4668719.html
>
> > Sent from the Users forum mailing list archive at Nabble.com.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> <http:///user/SendEmail.jtp?type=node&node=4668721&i=2>
> > For additional commands, e-mail: [hidden email]
> <http:///user/SendEmail.jtp?type=node&node=4668721&i=3>
> >
> >
> If you reply to this email, your message will be added to the discussion
> below:
>
> http://apache-wicket.1842946.n4.nabble.com/How-to-instruct-RenderPageRequestHandler-to-redirect-using-301-Permanent-tp4668716p4668721.html
> To unsubscribe from How to instruct RenderPageRequestHandler to redirect
> using 301 Permanent, click here
> <http://apache-wicket.1842946.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4668716&code=aGVuZHlAc29sdXZhcy5jb218NDY2ODcxNnwxNTI0Njc4NzUy>
> .
> NAML
> <http://apache-wicket.1842946.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/How-to-instruct-RenderPageRequestHandler-to-redirect-using-301-Permanent-tp4668716p4668722.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: How to instruct RenderPageRequestHandler to redirect using 301 Permanent
Posted by Martin Grigorov <mg...@apache.org>.
RequestCycle.get().urlFor(pageClass, parameters)
Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov
On Wed, Dec 10, 2014 at 3:20 PM, Hendy Irawan <he...@soluvas.com> wrote:
> Thanks for prompt advice Martin, however please explain more... I commented
> that code because I don't know how to construct the redirectUrl String from
> a PageProvider, inside RequestMapper.mapRequest? (Or alternatively, from
> PageClass + PageParameters)
>
> Hoping you can shed light on this.
> Thanks in advance.
>
> Hendy
>
> On Wed, Dec 10, 2014, 20:12 Martin Grigorov-4 [via Apache Wicket] <
> ml-node+s1842946n4668717h25@n4.nabble.com> wrote:
>
> > Hi,
> >
> > To do a "normal" redirect Wicket
> > uses javax.servlet.http.HttpServletResponse#sendRedirect() and this sets
> > 302 as a code.
> > To have better control you should use RedirectRequestHandler, as in your
> > commented out code.
> >
> > Martin Grigorov
> > Wicket Training and Consulting
> > https://twitter.com/mtgrigorov
> >
> > On Wed, Dec 10, 2014 at 2:56 PM, Hendy Irawan <[hidden email]
> > <http:///user/SendEmail.jtp?type=node&node=4668717&i=0>> wrote:
> >
> > > I currently have a custom SEO-friendly RequestMapper with the following
> > > snippet:
> > >
> > > @Override
> > > public final IRequestHandler mapRequest(Request request) {
> > > try {
> > > final String userAgent = ((HttpServletRequest)
> > > request.getContainerRequest()).getHeader("User-Agent");
> > > final RedirectPolicy redirectPolicy = userAgent != null
> > &&
> > > BotUtils.isBot(userAgent) ? RedirectPolicy.NEVER_REDIRECT :
> > > RedirectPolicy.AUTO_REDIRECT;
> > >
> > > final UrlInfo urlInfo = parseRequest(request);
> > >
> > > // check if the URL is long enough and starts with the
> > > proper segments
> > > if (urlInfo != null)
> > > {
> > > PageComponentInfo info =
> > > urlInfo.getPageComponentInfo();
> > > Class<? extends IRequestablePage> pageClass =
> > > urlInfo.getPageClass();
> > > PageParameters pageParameters =
> > > urlInfo.getPageParameters();
> > >
> > > if (info == null)
> > > {
> > > // if there are is no page instance
> > > information
> > > // then this is a simple bookmarkable
> > URL
> > > return processBookmarkable(pageClass,
> > > pageParameters, redirectPolicy);
> > > }
> > > else if (info.getPageInfo().getPageId() != null
> > &&
> > > info.getComponentInfo() == null)
> > > {
> > > // if there is page instance
> information
> > > in the URL but no component and
> > > listener
> > > // interface then this is a hybrid URL
> -
> > > we need to try to reuse
> > > existing page
> > > // instance
> > > return
> processHybrid(info.getPageInfo(),
> > > pageClass, pageParameters,
> > > null);
> > > }
> > > else if (info.getComponentInfo() != null)
> > > {
> > > // with both page instance and
> > > component+listener this is a listener
> > > interface URL
> > > return processListener(info, pageClass,
> > > pageParameters);
> > > }
> > > else if (info.getPageInfo().getPageId() ==
> null)
> > > {
> > > return processBookmarkable(pageClass,
> > > pageParameters, redirectPolicy);
> > > }
> > >
> > > }
> > > return null;
> > > } catch (MapperRedirectException e) {
> > > log.debug("Redirecting '{}' to canonical page: {}",
> > > request.getUrl(),
> > > e.getPageProvider());
> > > // return new RedirectRequestHandler(redirectUrl,
> > > 301);
> > > return new
> RenderPageRequestHandler(e.getPageProvider(),
> > > RedirectPolicy.ALWAYS_REDIRECT);
> > > }
> > > }
> > >
> > > What it does is allow freeform root URI paths, e.g.
> > > http://www.tuneeca.com/t-1113012 instead of the longer
> > > http://www.tuneeca.com/product/t-1113012 .
> > >
> > > Now, requests to http://www.tuneeca.com/product/t-1113012 are also
> > handled
> > > by the same RequestMapper and will be redirected to
> > > http://www.tuneeca.com/t-1113012 .
> > >
> > > However, currently it's using 302 temporary redirect. How to make it
> use
> > > 301
> > > permanent redirect?
> > >
> > > Thank you.
> > >
> > > Hendy
> > >
> > >
> > > --
> > > View this message in context:
> > >
> >
> http://apache-wicket.1842946.n4.nabble.com/How-to-instruct-RenderPageRequestHandler-to-redirect-using-301-Permanent-tp4668716.html
> > > Sent from the Users forum mailing list archive at Nabble.com.
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [hidden email]
> > <http:///user/SendEmail.jtp?type=node&node=4668717&i=1>
> > > For additional commands, e-mail: [hidden email]
> > <http:///user/SendEmail.jtp?type=node&node=4668717&i=2>
> > >
> > >
> >
> >
> > ------------------------------
> > If you reply to this email, your message will be added to the discussion
> > below:
> >
> >
> http://apache-wicket.1842946.n4.nabble.com/How-to-instruct-RenderPageRequestHandler-to-redirect-using-301-Permanent-tp4668716p4668717.html
> > To unsubscribe from How to instruct RenderPageRequestHandler to redirect
> > using 301 Permanent, click here
> > <
> http://apache-wicket.1842946.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4668716&code=aGVuZHlAc29sdXZhcy5jb218NDY2ODcxNnwxNTI0Njc4NzUy
> >
> > .
> > NAML
> > <
> http://apache-wicket.1842946.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml
> >
> >
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/How-to-instruct-RenderPageRequestHandler-to-redirect-using-301-Permanent-tp4668716p4668719.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
Re: How to instruct RenderPageRequestHandler to redirect using 301
Permanent
Posted by Hendy Irawan <he...@soluvas.com>.
Thanks for prompt advice Martin, however please explain more... I commented
that code because I don't know how to construct the redirectUrl String from
a PageProvider, inside RequestMapper.mapRequest? (Or alternatively, from
PageClass + PageParameters)
Hoping you can shed light on this.
Thanks in advance.
Hendy
On Wed, Dec 10, 2014, 20:12 Martin Grigorov-4 [via Apache Wicket] <
ml-node+s1842946n4668717h25@n4.nabble.com> wrote:
> Hi,
>
> To do a "normal" redirect Wicket
> uses javax.servlet.http.HttpServletResponse#sendRedirect() and this sets
> 302 as a code.
> To have better control you should use RedirectRequestHandler, as in your
> commented out code.
>
> Martin Grigorov
> Wicket Training and Consulting
> https://twitter.com/mtgrigorov
>
> On Wed, Dec 10, 2014 at 2:56 PM, Hendy Irawan <[hidden email]
> <http:///user/SendEmail.jtp?type=node&node=4668717&i=0>> wrote:
>
> > I currently have a custom SEO-friendly RequestMapper with the following
> > snippet:
> >
> > @Override
> > public final IRequestHandler mapRequest(Request request) {
> > try {
> > final String userAgent = ((HttpServletRequest)
> > request.getContainerRequest()).getHeader("User-Agent");
> > final RedirectPolicy redirectPolicy = userAgent != null
> &&
> > BotUtils.isBot(userAgent) ? RedirectPolicy.NEVER_REDIRECT :
> > RedirectPolicy.AUTO_REDIRECT;
> >
> > final UrlInfo urlInfo = parseRequest(request);
> >
> > // check if the URL is long enough and starts with the
> > proper segments
> > if (urlInfo != null)
> > {
> > PageComponentInfo info =
> > urlInfo.getPageComponentInfo();
> > Class<? extends IRequestablePage> pageClass =
> > urlInfo.getPageClass();
> > PageParameters pageParameters =
> > urlInfo.getPageParameters();
> >
> > if (info == null)
> > {
> > // if there are is no page instance
> > information
> > // then this is a simple bookmarkable
> URL
> > return processBookmarkable(pageClass,
> > pageParameters, redirectPolicy);
> > }
> > else if (info.getPageInfo().getPageId() != null
> &&
> > info.getComponentInfo() == null)
> > {
> > // if there is page instance information
> > in the URL but no component and
> > listener
> > // interface then this is a hybrid URL -
> > we need to try to reuse
> > existing page
> > // instance
> > return processHybrid(info.getPageInfo(),
> > pageClass, pageParameters,
> > null);
> > }
> > else if (info.getComponentInfo() != null)
> > {
> > // with both page instance and
> > component+listener this is a listener
> > interface URL
> > return processListener(info, pageClass,
> > pageParameters);
> > }
> > else if (info.getPageInfo().getPageId() == null)
> > {
> > return processBookmarkable(pageClass,
> > pageParameters, redirectPolicy);
> > }
> >
> > }
> > return null;
> > } catch (MapperRedirectException e) {
> > log.debug("Redirecting '{}' to canonical page: {}",
> > request.getUrl(),
> > e.getPageProvider());
> > // return new RedirectRequestHandler(redirectUrl,
> > 301);
> > return new RenderPageRequestHandler(e.getPageProvider(),
> > RedirectPolicy.ALWAYS_REDIRECT);
> > }
> > }
> >
> > What it does is allow freeform root URI paths, e.g.
> > http://www.tuneeca.com/t-1113012 instead of the longer
> > http://www.tuneeca.com/product/t-1113012 .
> >
> > Now, requests to http://www.tuneeca.com/product/t-1113012 are also
> handled
> > by the same RequestMapper and will be redirected to
> > http://www.tuneeca.com/t-1113012 .
> >
> > However, currently it's using 302 temporary redirect. How to make it use
> > 301
> > permanent redirect?
> >
> > Thank you.
> >
> > Hendy
> >
> >
> > --
> > View this message in context:
> >
> http://apache-wicket.1842946.n4.nabble.com/How-to-instruct-RenderPageRequestHandler-to-redirect-using-301-Permanent-tp4668716.html
> > Sent from the Users forum mailing list archive at Nabble.com.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> <http:///user/SendEmail.jtp?type=node&node=4668717&i=1>
> > For additional commands, e-mail: [hidden email]
> <http:///user/SendEmail.jtp?type=node&node=4668717&i=2>
> >
> >
>
>
> ------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
>
> http://apache-wicket.1842946.n4.nabble.com/How-to-instruct-RenderPageRequestHandler-to-redirect-using-301-Permanent-tp4668716p4668717.html
> To unsubscribe from How to instruct RenderPageRequestHandler to redirect
> using 301 Permanent, click here
> <http://apache-wicket.1842946.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4668716&code=aGVuZHlAc29sdXZhcy5jb218NDY2ODcxNnwxNTI0Njc4NzUy>
> .
> NAML
> <http://apache-wicket.1842946.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/How-to-instruct-RenderPageRequestHandler-to-redirect-using-301-Permanent-tp4668716p4668719.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: How to instruct RenderPageRequestHandler to redirect using 301 Permanent
Posted by Martin Grigorov <mg...@apache.org>.
Hi,
To do a "normal" redirect Wicket
uses javax.servlet.http.HttpServletResponse#sendRedirect() and this sets
302 as a code.
To have better control you should use RedirectRequestHandler, as in your
commented out code.
Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov
On Wed, Dec 10, 2014 at 2:56 PM, Hendy Irawan <he...@soluvas.com> wrote:
> I currently have a custom SEO-friendly RequestMapper with the following
> snippet:
>
> @Override
> public final IRequestHandler mapRequest(Request request) {
> try {
> final String userAgent = ((HttpServletRequest)
> request.getContainerRequest()).getHeader("User-Agent");
> final RedirectPolicy redirectPolicy = userAgent != null &&
> BotUtils.isBot(userAgent) ? RedirectPolicy.NEVER_REDIRECT :
> RedirectPolicy.AUTO_REDIRECT;
>
> final UrlInfo urlInfo = parseRequest(request);
>
> // check if the URL is long enough and starts with the
> proper segments
> if (urlInfo != null)
> {
> PageComponentInfo info =
> urlInfo.getPageComponentInfo();
> Class<? extends IRequestablePage> pageClass =
> urlInfo.getPageClass();
> PageParameters pageParameters =
> urlInfo.getPageParameters();
>
> if (info == null)
> {
> // if there are is no page instance
> information
> // then this is a simple bookmarkable URL
> return processBookmarkable(pageClass,
> pageParameters, redirectPolicy);
> }
> else if (info.getPageInfo().getPageId() != null &&
> info.getComponentInfo() == null)
> {
> // if there is page instance information
> in the URL but no component and
> listener
> // interface then this is a hybrid URL -
> we need to try to reuse
> existing page
> // instance
> return processHybrid(info.getPageInfo(),
> pageClass, pageParameters,
> null);
> }
> else if (info.getComponentInfo() != null)
> {
> // with both page instance and
> component+listener this is a listener
> interface URL
> return processListener(info, pageClass,
> pageParameters);
> }
> else if (info.getPageInfo().getPageId() == null)
> {
> return processBookmarkable(pageClass,
> pageParameters, redirectPolicy);
> }
>
> }
> return null;
> } catch (MapperRedirectException e) {
> log.debug("Redirecting '{}' to canonical page: {}",
> request.getUrl(),
> e.getPageProvider());
> // return new RedirectRequestHandler(redirectUrl,
> 301);
> return new RenderPageRequestHandler(e.getPageProvider(),
> RedirectPolicy.ALWAYS_REDIRECT);
> }
> }
>
> What it does is allow freeform root URI paths, e.g.
> http://www.tuneeca.com/t-1113012 instead of the longer
> http://www.tuneeca.com/product/t-1113012 .
>
> Now, requests to http://www.tuneeca.com/product/t-1113012 are also handled
> by the same RequestMapper and will be redirected to
> http://www.tuneeca.com/t-1113012 .
>
> However, currently it's using 302 temporary redirect. How to make it use
> 301
> permanent redirect?
>
> Thank you.
>
> Hendy
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/How-to-instruct-RenderPageRequestHandler-to-redirect-using-301-Permanent-tp4668716.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>