只需创建一个RedirectorPage
并选择第一个子页面作为重定向目标,即可在没有任何附加代码的情况下实现“虚拟”页面。
就我个人而言,过去我使用了一个更简单的“RedirectorPage”版本,如果直接访问它,它会自动重定向到第一个子页面。
例子:
class ChildRedirectorPage extends Page
{
private static $description = 'Page that has no content but automatically redirects to the first of its child-pages';
public function ContentSource() {
if($firstChild = $this->Children()->First()) {
return $firstChild;
} else {
return $this;
}
}
public function Link($action = null) {
// prevent link "redirection" when we're in CMS
if (!is_subclass_of(Controller::curr(),'LeftAndMain')){
if($firstChild = $this->Children()->First()) return $firstChild->Link($action);
else return parent::Link($action);
}
}
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->removeByName('Content', true);
return $fields;
}
}
class ChildRedirectorPage_Controller extends Page_Controller
{
function init() {
parent::init();
if($firstChild = $this->Children()->First()) {
$this->redirect($firstChild->Link(), 301);
}
}
}
我觉得URL蛞蝓实际上是有益的,因为你的网址,于是将services/peeling-potatoes
等,这是最有可能更好的搜索引擎优化的目的。