How to setup a route in CakePHP How to setup a route in CakePHP

If you are like me and are creating personal web sites, one of the best ways to gain traffic to your site is through SEO.† I won't go into detail here as I want to focus on how to setup a route in CakePHP, but having SEO friendly URLs will go a long way in helping.

First let's define what a "route" is.† In CakePHP it allows you to add a different path to access a specific controller and/or function in that controller.

For example, let's say I want to create a CMS.† I might create a controller called "StaticContent" and then place a function for each page a client would like to create.† I'm pretty sure I would start getting a lot of calls saying, "Jamie, why is my URL"† So to avoid those calls, we can use a route to make it more accessible and SEO friendly.

To create our route it's quite simple, open up app/config/routes.php in your editor of choice.† To create a route for our static content, we would create something like this (you will need to update the names accordingly for your purpose):

Router::connect('/seo-friendly-url', array('controller' => 'StaticContent', 'action' => 'unSeoFriendlyURL'));

The syntax above is saying, if we find the URL "/seo-friendly-url", CakePHP should look for the content in the StaticContent controller and our unSeoFriendlyURL function.

The above example is a great way of how you can quickly create SEO friendly URLs and continue to create controllers and functions as you normally would.

Hopefully you have enjoyed today's article, I am going to try and continue to create some more short and useful CakePHP examples.

Published on Mar 5, 2009

Tags: SEO (Search Engine Optimization) | CakePHP Tutorial | seo

Related Posts

Did you enjoy this article? If you did here are some more articles that I thought you will enjoy as they are very similar to the article that you just finished reading.


Learn how to code in HTML, CSS, JavaScript, Python, Ruby, PHP, Java, C#, SQL, and more.

No matter the programming language you're looking to learn, I've hopefully compiled an incredible set of tutorials for you to learn; whether you are beginner or an expert, there is something for everyone to learn. Each topic I go in-depth and provide many examples throughout. I can't wait for you to dig in and improve your skillset with any of the tutorials below.