CakePHP Tip: Routing for static pages
Woo, my first CakePHP Tip!
Add the following to /app/config/routes.php:
Router::connect(‘/contact’, array(‘controller’ => ‘pages’, ‘action’ => ‘display’, ‘contact’));
and create your contact page at:
/app/views/pages/contact.ctp
You can now access the contact page at:

Awesome! I have been looking for a way to do exactly this without creating a PagesController, or any database nonsense.
Aaron Thies said this on January 23, 2008 at 6:23 pm
Thanks !
protospike said this on July 9, 2008 at 6:15 pm
[...] Routing for Static Pages Share and Enjoy: [...]
Aaron Thies » Blog Archive » Remove Pages from Static Pages said this on July 28, 2008 at 3:21 am
Excellent tip!
Luke said this on August 7, 2008 at 6:49 am
And what’s great about this, is if you’re using the Auth component in app_controller.php, it still does all the auth stuff if you have it in a beforeFilter in app_controller.php. Again, for anybody that’s reading, if you have an app that needs authentication, but needs authorization on some, but not all pages, you can use this tip to make your non-authenticated pages.
Ben said this on August 24, 2008 at 7:50 am
I’m using cakePHP 1.2 RC2 and it has a default routing for static pages into a URL (http://foo.com/pages/contact)
Hazem said this on September 14, 2008 at 9:32 am
But I found this very useful anyway
Hazem said this on September 14, 2008 at 9:33 am
Hazem, the tip means you don’t need the /pages/ part of the url. It means you can have url’s like:
http://foo.com/contact
http://foo.com/about
etc.
Richard@Home said this on September 14, 2008 at 12:35 pm
I just changed my route to the following:
Router::connect(‘*’, array(‘controller’ => ‘pages’, ‘action’ => ‘display’));
This way you don’t need to create a new one for each static page, and works for any in the pages folder.
Mathieu said this on September 15, 2008 at 1:00 pm
@Mathieu: I *think* that’s great for a site with all static pages, but I think you might hit a problem with dynamic pages that uses a controller other than the pages controller.
Basically, you’re routing rule says: For every page, pass it to the page controllers display method.
What will you do if you need to display the Users->login() action?
Richard@Home said this on September 15, 2008 at 9:23 pm
Richard, It is a good tip. But arent you hard coding the static content into a view. I know it works best for a website with minimal static content, but in implementing a CMS with lots of static content, it may not be useful to hard code the static content into a view. What say?
But it is a clever idea nevertheless.
-Ravi
Ravi said this on April 19, 2009 at 11:39 am
thanks buddy keep up the good work
kannan said this on July 30, 2009 at 11:25 am
iam new to cakephp
i have followed all these steps when i test in on a local server
http://localhost/cake_php/contact
it shows my only a blank page, (no contents are shown in the page )
Please help me regarding static page
leo said this on September 7, 2009 at 7:29 am
I am having the same issue. I followed the directions, but no contents are shown when I try to access the page. Any ideas why it’s not showing up?
AR said this on December 11, 2009 at 7:03 pm
Extremely useful, cheers for sharing this excellent Cake PHP tip on static pages without the /pages/ bit.
Kate C2 said this on February 4, 2010 at 5:32 pm
If you don’t want to have the default layout associate with the static view.ctp then just place with at the very top of your view.ctp file layout = null; ?>
JP said this on August 9, 2010 at 2:27 pm
For those of you who are having difficulty displaying the page (a blank page or a 404 error), make sure that you have the proper .htaccess file(s) in your folders. Refer to this page for directions….
http://book.cakephp.org/view/37/Apache-and-mod_rewrite-and-htaccess
I was getting 404s and it’s because I didn’t have my .htaccess files.
/.htaccess
/app/.htaccess
Hope this helps!
Philip said this on August 30, 2010 at 12:29 am
. Hi, i really liked this article.. Thanx for sharing. . it prove very beneficial for me.
Alex said this on June 28, 2011 at 9:21 am
I have created the static page by using your post,but that is not working. advice me.
Mercy said this on August 1, 2011 at 1:22 pm
Hi, I tried your tip but it keeps taking me to default page.
bhawna said this on October 17, 2011 at 7:38 am
Thanks…
Very Helpful post for me.
keep posting…
Ankur Jain said this on December 15, 2011 at 12:30 pm
Great! This is what I need…
Genesis said this on April 21, 2012 at 3:59 pm
I’d like to send this letter by http://doynonoko.de.tl teen nymphet erotica The chick is hot and the dude is crazy ;D But I feel like the girl is doin to much with the extra
Oecqpful said this on May 3, 2012 at 1:22 pm