Developer forum

Forum » CMS - Standard features » Redirect to first subpage / most recently added subpage

Redirect to first subpage / most recently added subpage

Rene Poulsen
Reply

Hi,

I was wondering if it's possible to always redirect a page to the first child-/subpage. I have a "news" page, with a lot of subpages which are the actual news. When i click "news" in the menu, I would like the page to redirect to the first subpage (it changes over time) or the most recently added page.

I'm almost sure it's not possible to do with standard functionality, but maybe it could be possible to do via. a razor template? But how? :-)

 

 

 

 

 


Replies

 
Rene Poulsen
Reply

Figured it out. By using a razor template I'm able to do the following:

@{
	Dynamicweb.Frontend.PageView pv = Dynamicweb.Frontend.PageView.Current();
	Dynamicweb.Content.PageCollection pc = Dynamicweb.Content.Page.GetPagesByParentID(pv.Page.ID);
	
	string firstsubpageid = pc[0].ID.ToString();
	
	System.Web.HttpContext.Current.Response.Redirect("default.aspx?id=" + firstsubpageid);
}

I get the current PageView. With the PageID of the PageView I'm able to get all subpages (a PageCollection) to the current page. The collection is sorted in the same way the pages are sorted in the dw backend, so I can get the first page in the PageCollection and redirect to that page.

With SEO in mind, I don't know if the redirect has to be done in another way? I guess a 301 Permanently Moved wouldn't be the correct way - as the page it redirects to changes over time.

 

 

 

 

 
Nicolai Høeg Pedersen
Reply

Hi Rene

 

Good solution and shows why Razor is nice some times.

 

With regards to the redirect, yes you should use the 302 in your example above since the redirect will change every now and then.

 

BR Nicolai

 

You must be logged in to post in the forum