[CLOSED] Question about 404 page

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Locked
rooon
Forum Members
Forum Members
Posts: 113
Joined: Mon Dec 05, 2011 4:40 pm

[CLOSED] Question about 404 page

Post by rooon »

Hello,

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 );
      }
   }
}
Array
- 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.
Last edited by rooon on Tue Feb 16, 2016 2:06 pm, edited 1 time in total.
rooon
Forum Members
Forum Members
Posts: 113
Joined: Mon Dec 05, 2011 4:40 pm

Re: Question about 404 page

Post by rooon »

After searching the cmsms 1.11 files I found this (semi)code

Code: Select all

if exist('error404')
   // next header with content of page error404 (index.php)
   header("HTTP/1.0 404 Not Found");
   header("Status: 404 Not Found");
else
   // next header with default text (misc.functions.php)
   header("HTTP/1.0 404 Not Found");
   header("Status: 404 Not Found");
The answer of my question:
There will always be a 404 header if the page doesn't exist (with or without the 404 page). Ofcourse, that's the way it's supposed to work :) but for me the UDT is not working the way I want.

So I have to think about another solution. In the config.php maybe?
Locked

Return to “Modules/Add-Ons”