Free Android CakePHP GMaps Articles by Bali Web Design

September 4, 2010

How to redirect wordpress blog url cakephp

Filed under: cakephp,php,wordpress — admin @ 7:15 pm

Cakephp have great routing capability, i was install wordpress blog on my main website root directory. And then i need to move my blog into new folder, i put it on /app/webroot/blog/ because i build new web application on root directory using cakephp.

I use rewriting rule for my wordpress blog. The rule is I want to redirect into I don’t want to loose my blog visitors because the blog posting has good ranking on google.

So i do setting on app/config/routes.php and add this line

Router::connect(‘/:year/:month/:slug’, array(‘controller’ => ‘pages’, ‘action’ => ‘redirect_blog’), array(‘pass’ => array(‘year’, ‘month’, ‘slug’), ‘year’ => ‘[0-9]{4}’, ‘month’ => ‘[0-9]{2}’, ‘slug’ => ‘[A-Za-z0-9-]+’));

I add new method redirect_blog on app/controllers/pages_controller.php. The complete code for redirect_blog are like below

function redirect_blog() {
$this->redirect('/blog/'. $this->params['url']['url'], 303);

303 is permanent redirection status. Actually i don’t need to pass pass parameter on my routes, but i would like to add there if you need another redirection rule for your blog. You can try to print $this->params to see all parameters passed. On my application $this->params look like this :

    [year] => 2010
    [month] => 08
    [slug] => how-to-redirect-appwebrootblog-into-blog-wordpress-cakephp
    [named] => Array

    [pass] => Array
            [0] => 2010
            [1] => 08
            [2] => how-to-redirect-appwebrootblog-into-blog-wordpress-cakephp

    [controller] => pages
    [action] => redirect_blog
    [plugin] =>
    [url] => Array
            [ext] => html
            [url] => 2010/08/how-to-redirect-appwebrootblog-into-blog-wordpress-cakephp/

    [form] => Array


This is how i set cakephp routing for redirect my old blog url into new blog folder url.

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment