Redirect to the childpage

Permalink
Hello,

i wanted to know if there is a possibility to redirect the visitor to a childpage ? Here's the case:

/Home
.. /en
.... /Page 1
.... /Page 2
.. /fr
.... /Page 1

If someone typeshttp://site.tld/en in the browser, i want that the visitor gets redirected to the first child in the list (Page 1). Is there something for that like those other handlers (ex. replace_link_with_first_in_nav) ?

Thanks

marcandre
 
Ale replied on at Permalink Reply
A very late reply, found this one by searching and I'd like to get some info on same topic..

I've ran into same problem and solved it this way:

First, I created a custom attribute called "Redirect to first childpage" with handle redirect_to_first_child. Then, I added the following lines to my theme's header.php

global $c; //not sure if actually needed
if($c->getCollectionAttributeValue('redirect_to_first_child') == 1) {
 $firstChild = $c->getFirstChild();
 $path = $firstChild->getCollectionPath();
 if($path == "/login") {
  $path = "/en";
 }
header('location: '.BASE_URL.DIR_REL.$path);
}


In some cases I had the user redirected to login page, hence the check for login path and redirect to first page under /en. Also, if you are not using pretty urls, put the last line this way:

header('location: '.BASE_URL.DIR_REL."/index.php".$path);


This solves the problem, but I'm not sure if this is the most efficient way. It would be nice to get some feedback how to implement the feature more efficiently. Also, the full page cache needs to be manually disabled for the pages that have redirect attribute, otherwise the redirect won't work. However, I'd really like to see this feature as part of the C5 core with ready-made attributes available on default install.
jordanlev replied on at Permalink Reply
jordanlev
This functionality was added to the core system a while ago -- see "replace_link_with_first_in_nav" inhttp://www.concrete5.org/documentation/how-tos/built-in-attribute-r...
Ale replied on at Permalink Reply
I'm fully aware of "replace_link_with_first_in_nav", but it only works with autonav blocks. If you read the first message carefully, you see that the problem is how to redirect user automatically tohttp://www.yoursite.com/en when he typeshttp://www.yoursite.com to browser's address bar. Replacing links won't solve this problem.
Ale replied on at Permalink Reply
Actually some other users are dealing with the problem in this thread:

http://www.concrete5.org/community/forums/customizing_c5/how-do-i-m...

There is same kind of solution as mine in that thread, but I'd like to see the feature added to core.