Today I coded this UDT {redirect_301 getpage=$smarty.get.page} for using on the 404 page. This will 301 redirect non-existing page url's to an alias that is specified in the UDT. If you do not specify the url, then the page will not be redirected.
Code: Select all
$moved = array(
####### BEGIN REDIRECT LIST #####################
"products/item/old-page" => "new-page",
"contact/form" => "contact",
"about/address" => "about-us",
####### END REDIRECT LIST #####################
);
$getpage = (isset($params['getpage'])) ? trim($params['getpage']) : '';
$info = pathinfo($getpage);
$ext = (isset($info['extension'])) ? '.' . $info['extension'] : '';
$dir = (substr(dirname($getpage), 0, 1) != '.') ? dirname($getpage) . '/' : '';
$getpage = $dir . basename($getpage, $ext);
if ( array_key_exists($getpage, $moved) ) {
$gCms = cmsms();
$smarty = $gCms->GetSmarty();
$contentops = $gCms->GetContentOperations();
$content = $contentops->LoadContentFromAlias($moved[$getpage]);
if( is_object($content) ) {
$url = $content->GetUrl();
if( isset($params['assign']) ){
$smarty->assign(trim($params['assign']), $url);
}else{
header( 'HTTP/1.1 301 Moved Permanently' );
header( 'Location: ' . $url );
}
}
}
- Use the array as: "non/existing/url" => "alias",
- Each line must end with a comma
- The url must be relative to the cms root
- Do not use a leading or trailing slash
- Do not specify .php, .html, # or ? query in the array list
My question:
When cmsms forwards a non-existing page to the 404 page, is then the header set to 404 page not found? Or is it only an internal link?
This question because I do not want a header with 404, followed by a 301.
Thanx in advance for your reply.
Ronald
Update: the end-user is not familiair with htaccess and therefor I was searching for a simple to manage solution for him.

