Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7457853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T13:22:31+00:00 2026-05-29T13:22:31+00:00

All, I am currently using CakePHP to completely revamp my current NEWS site. I

  • 0

All,

I am currently using CakePHP to completely revamp my current NEWS site. I have or will transfer all current articles to my new site and they will take on the same article_id as the current site. However, I have realized of the following problem.

My current site uses the following setup as URL:

http://www.mydomain.com/?c=140&a=4388

c=references the category ID and a=references the article ID. My new setup (CakePHP) I take advantage of slugs and now my articles URLs display as:

http://www.mydomain.com/noticia/this-is-an-article-slug

Since, I have noticed, thru webstats, that many of my articles are accessed thru links setup on other sites like Facebook, I thought it would be crucial to create a system/route that will take care of this issue for me.

This is what I am thinking:

  1. Create a route that detects requests similar to what is mentioned above
  2. Make the route pass the a value as parameter to a redirect function in my articles controller, such as articleRedirect($article_id)
  3. This function would then look up in the database for slug based on the passed $article_id and redirect to the new address (See function below)

    // Function in articles controller to redirect old site's article url to 
    // new websites url format
    
    function articleRedirect($article_id = NULL){
        $this->Article->recursive = -1;
        $slug = $this->Article->findById($article_id);        
        if($slug == NULL){
            $this->Session->setFlash('Article not found');
            $this->redirect('/noticias');
        }else{
            $this->redirect('/noticia/'.$slug['Article']['slug']);
        }
    }
    

I think that should work. However, I need some serious help with routing. Can anyone suggest a route I can use.

Thank you very much.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T13:22:31+00:00Added an answer on May 29, 2026 at 1:22 pm

    Thanks for Oldskool for the willingness to help. However, I had trouble implementing it. I decided to stay away from using .htaccess or routes and opted to implement a function in app_controller that will handle it for me as such:

    In my app_controller's beforeFilter() I added the following:

    //Check old url style as in http://www.bravanews.com/?c=123&a=2345 for redirection
        //to the correct new url style as in http://www.bravanews.com/noticia/news-title-using-slug
        $this->CheckOldUrl();
    

    Then in my app_controller.php I created the following function:

    function CheckOldUrl(){
        preg_match("/\?c=(\w+)\&a=(\w+)/i", $_SERVER['REQUEST_URI'], $matches);
        if(!$matches == NULL){
            $this->redirect('/noticias/articleRedirect/'.$matches[2]);
        }
    }
    

    If old url the above function will transfer to the articleRedirect function which will then redirect to the right document

    // Function in articles controller to redirect old site's article url to 
    // new websites url format
    
    function articleRedirect($article_id = NULL){
        $this->Article->recursive = -1;
        $slug = $this->Article->findById($article_id);        
        if($slug == NULL){
            $this->Session->setFlash('Article not found');
            $this->redirect('/noticias');
        }else{
            $this->redirect('/noticia/'.$slug['Article']['slug']);
        }
    }
    

    It is probably not the best way to handle this kind of things this way since it makes a call to that function everytime time my site is accessed, but it is working for me without major problems.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

All - I am using WSS 3.0. Currently, HR will upload an employee's internal
How can I secure my CakePHP 1.3 site against XSS. Currently I am using
I'm currently using CakePHP 2.0-RC1. Being pretty nifty and all, I've only come across
I'm currently using jpathwatch to watch for new files created in a folder. All
I am currently using a catch all method for all inputs on my form
I'm currently using DPack as this adds a Collapse All Projects option to the
I'm currently using the following PHP code: // Get all subordinates $subords = array();
I'm currently using a certain ItemTemplate for three repeaters that are all on the
We are currently using Fitnesse for sub system testing. [All our applications are in
Is there a way using SWT to get a list of all processes currently

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.