internetearnings.com

SEO Friendly URL in CakePHP Pagination

By default, CakePHP Pagination will have “page:X” in the URL where X is the page number (except the first page). Many SEO expert feel that this type of URL is not SEO friendly. From webmaster point of view, this kind of URL doesn’t look nice too.

Let’s take an example, by default we will have pagination URL like this

http://www.website.com/post
http://www.website.com/post/page:2
http://www.website.com/post/page:3
...

we would like to change it to

http://www.website.com/post
http://www.website.com/post/page/2
http://www.website.com/post/page/3
...

We have to modify 3 files to get this done

1. /app/Config/routes.php

Add or modify the existing route to

Router::connect('/post/page/:page', array(
    'controller' => 'post',
    'action' => 'index'
), array(
    'pass' => array(
        'page'
    ),
    'page' => '[\d]+'
));

2. /app/Controller/PostsController.php

Add or modify the existing controller to

public function index($page = 1) {
    // ...
    $this->request->params['named']['page'] = $page;
    // ...
}

3. /app/View/Posts/index.ctp

Add or modify the existing view to

$paginator->options(array(
    'url'=> array(
        'controller' => 'post',
        'action' => 'index'
    )));

Fix the “PHP Fatal error: Call to undefined function get_header()” error in WordPress

Recently, I found out that there is a huge error log file (error_log) in my current theme folder. Upon checking the whole log file contains the following error.

[26-Apr-2014 16:01:14 UTC] PHP Fatal error: Call to undefined function get_header() in /home/user/public_html/www.website.com/wp-content/themes/mytheme/index.php on line 1
[26-Apr-2014 16:08:00 UTC] PHP Fatal error: Call to undefined function get_header() in /home/user/public_html/www.website.com/wp-content/themes/mytheme/index.php on line 1

Upon checking & try to reproduce the error, I find out that the error was generated each time when a visitor tries to access theme’s index.php file directly.

I’m not sure if there will be a security issue, but the error will expose your cPanel username if you are using it.

There are 2 methods on how to fix this problem.

1. Redirect it to main page. To do it, edit “index.php” in the root of theme folder & replace

<?php
get_header();
?>

with

<?php
if (defined('ABSPATH')) {
get_header();

}else{

header("Location: http://" . $_SERVER['HTTP_HOST'] . "");
exit;
}; ?>

2. Disable direct access of theme’s index file. To do it, edit “index.php” in the root of theme folder & replace

<?php
get_header();
?>

with

<?php
if (! defined('ABSPATH'))
die('Access Denied.');

get_header();
?>