You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Dirk Forchel <di...@exedio.com> on 2013/01/17 13:22:46 UTC

Re: Redirect to Wicket page with 301 Moved Permanently

Concerning Wicket 1.5/6:

I've mounted a page for example with a mount path like "product.html" and
with a query string (PageParameter) like "product.html?product=1234". This
is my old mounting path which has already been indexed by Google.
The new mounting path for the same page will look different, say
"product/product-name/1234".
To forward requests from obsolete links to the new one, I've added a kind of
"Redirect Page" which does nothing but redirecting to the new Url. The
redirect page is mounted with the old path.

public RedirectPage( final PageParameters parameters, final String url )
{
	super(parameters);
	throw new RedirectToUrlException( url ,
HttpServletResponse.SC_MOVED_PERMANENTLY );
}

If I would change the mounting path for more than 5 or 10 pages, this kind
of solution could be very annoying.
Is there another way to solve this. I would prefer something like a Map
which holds old and new mounth paths and a kind of "Mapper" which is
responsible to map obsolete URLs to new ones.
Exists such a solution which I'm not aware of?




--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Redirect-to-Wicket-page-with-301-Moved-Permanently-tp4631888p4655460.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: Redirect to Wicket page with 301 Moved Permanently

Posted by Dirk Forchel <di...@exedio.com>.
Sounds to complicated. Then I prefer the old fashioned way like this ...
Wicket generates the new Url based on a passed in "Product". I don't have to
bother about ".html" ending and segement sizes and so on ...

mountPage("product.html", LegacyProductPage.class);
mountPage("product/#{product_name}/${product}", ProductPage.class);

public abstract class AbstractRedirectPage extends WebPage
{
	public AbstractRedirectPage( final PageParameters parameters, final String
url )
	{
		this( parameters, url, HttpServletResponse.SC_MOVED_PERMANENTLY );
	}
	
	public AbstractRedirectPage( final PageParameters parameters, final String
url, int statusCode )
	{
		super(parameters);
		throw new RedirectToUrlException(toFullUrl( url ), statusCode );
	}
}

public class LegacyProductPage extends AbstractRedirectPage
{
	public LegacyProductPage( final PageParameters parameters, final Product
product )
	{
		super(parameters, getProductPageUrl(product));
	}

	private static String getProductPageUrl( Product product )
	{
		final PageInfo pageInfo = new ProductPage.PageInfo(product);
		return pageInfo.getRelativeUrl();
	}
}

public class ProductPage extends WebPage
{
	public static class PageInfo
	{
		final Product product;
		
		public PageInfo( Product product )
		{
			this.product = product;
		}

		public String getRelativeUrl()
		{
			return RequestCycle.get().urlFor( ProductPage.class,
pageParametersForProductPage( product ) ).toString();
		}

	}

	private final Product product;
	

	public ProductPage(final PageParameters pageParameters, final Product
product )
	{

        }
}



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Redirect-to-Wicket-page-with-301-Moved-Permanently-tp4631888p4655470.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: Redirect to Wicket page with 301 Moved Permanently

Posted by Martin Grigorov <mg...@apache.org>.
:-)
Read again what you just said - you (the application developer) don't know
the rules but Wicket (a generic framework) should know. How ? :-) Your
manager/customer is not embedded in Wicket to make the decisions :-)

Looking at the urls you showed earlier you have to check that the url ends
with ".html", has a segment for the category and there is such category in
your app domain, same for product. Something like this.


On Thu, Jan 17, 2013 at 3:30 PM, Dirk Forchel <di...@exedio.com>wrote:

> > You don't need to mountPage(TheLegacyPage) - it wont be used anyway.
>
> Yes, you are right. There is actually no need to do this.
> But I don't have a glue how to check whether the request URL is an obsolete
> one or not AND how to map the old parameters to the new parameters. So I
> thought, having both pages and let Wicket do the stuff for me would be a
> good starting point.
>
>
>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Redirect-to-Wicket-page-with-301-Moved-Permanently-tp4631888p4655468.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
>
>


-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com <http://jweekend.com/>

Re: Redirect to Wicket page with 301 Moved Permanently

Posted by Dirk Forchel <di...@exedio.com>.
> You don't need to mountPage(TheLegacyPage) - it wont be used anyway. 

Yes, you are right. There is actually no need to do this. 
But I don't have a glue how to check whether the request URL is an obsolete
one or not AND how to map the old parameters to the new parameters. So I
thought, having both pages and let Wicket do the stuff for me would be a
good starting point.





--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Redirect-to-Wicket-page-with-301-Moved-Permanently-tp4631888p4655468.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: Redirect to Wicket page with 301 Moved Permanently

Posted by Martin Grigorov <mg...@apache.org>.
You don't need to mountPage(TheLegacyPage) - it wont be used anyway.
The requests to the old urls will be server by the new request
mapper/handler.


On Thu, Jan 17, 2013 at 3:06 PM, Dirk Forchel <di...@exedio.com>wrote:

> Hm, I already thought about that. But I miss the link between the old
> mounted
> pages and the new pages. I mean I have to mount a pair of page classes
> though.
>
> mountPage("product.html", LegacyProductPage.class);
> mountPage("product/#{product_name}/${product}", ProductPage.class)
>
> And in the new Mapper would check like (don't know whether this works):
>
> @Override
> public final IRequestHandler mapRequest(Request request)
> {
>    IRequestHandler handler = delegate.mapRequest(request);
>    // check whether the request is a legacy URL
>    if (isLegacyUrl(request)
>   {
>       // get the new URL instead
>       String url = createRedirectUrl(handler, request);
>       handler = createRedirectHandler(url);
>    }
>    return handler
> }
>
> Just what I have in mind. The new mapper would hold a map with a pair of
> "legacy" and "new" Page classes. And for each request the mapper would
> check
> whether this request URL is contained in the map. But this means I have to
> maintain two places for each pair of "legacy" and "new" Page classes. I'm
> not sure whether this is a smart solution.
>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Redirect-to-Wicket-page-with-301-Moved-Permanently-tp4631888p4655465.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
>
>


-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com <http://jweekend.com/>

Re: Redirect to Wicket page with 301 Moved Permanently

Posted by Dirk Forchel <di...@exedio.com>.
Hm, I already thought about that. But I miss the link between the old mounted
pages and the new pages. I mean I have to mount a pair of page classes
though.

mountPage("product.html", LegacyProductPage.class);
mountPage("product/#{product_name}/${product}", ProductPage.class)

And in the new Mapper would check like (don't know whether this works):

@Override
public final IRequestHandler mapRequest(Request request)
{
   IRequestHandler handler = delegate.mapRequest(request);
   // check whether the request is a legacy URL
   if (isLegacyUrl(request)
  {
      // get the new URL instead
      String url = createRedirectUrl(handler, request);
      handler = createRedirectHandler(url);
   }
   return handler 
}

Just what I have in mind. The new mapper would hold a map with a pair of
"legacy" and "new" Page classes. And for each request the mapper would check
whether this request URL is contained in the map. But this means I have to
maintain two places for each pair of "legacy" and "new" Page classes. I'm
not sure whether this is a smart solution. 



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Redirect-to-Wicket-page-with-301-Moved-Permanently-tp4631888p4655465.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: Redirect to Wicket page with 301 Moved Permanently

Posted by Martin Grigorov <mg...@apache.org>.
There is no such functionality in Wicket.
But all you need is a custom IRequestMapper, override its #mapRequest(Url)
method and return a custom IRequestHandler that does the redirect.


On Thu, Jan 17, 2013 at 2:22 PM, Dirk Forchel <di...@exedio.com>wrote:

> Concerning Wicket 1.5/6:
>
> I've mounted a page for example with a mount path like "product.html" and
> with a query string (PageParameter) like "product.html?product=1234". This
> is my old mounting path which has already been indexed by Google.
> The new mounting path for the same page will look different, say
> "product/product-name/1234".
> To forward requests from obsolete links to the new one, I've added a kind
> of
> "Redirect Page" which does nothing but redirecting to the new Url. The
> redirect page is mounted with the old path.
>
> public RedirectPage( final PageParameters parameters, final String url )
> {
>         super(parameters);
>         throw new RedirectToUrlException( url ,
> HttpServletResponse.SC_MOVED_PERMANENTLY );
> }
>
> If I would change the mounting path for more than 5 or 10 pages, this kind
> of solution could be very annoying.
> Is there another way to solve this. I would prefer something like a Map
> which holds old and new mounth paths and a kind of "Mapper" which is
> responsible to map obsolete URLs to new ones.
> Exists such a solution which I'm not aware of?
>
>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Redirect-to-Wicket-page-with-301-Moved-Permanently-tp4631888p4655460.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
>
>


-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com <http://jweekend.com/>