I finished a simple cms in cakephp but noticed that url are not that preety looking. As for displaying any page url looks like cakephp/pages/1. What would be the good way to make it look better and SEO friendly?
3 Answers
links:
cakephp/pages/page_title_here
cakephp/pages/another_example_page_title
controller:
class Pages extends CI_Controller {
public function index($page = false)
{
if($page && file_exists('./application/views/pages/'.$page.'.php')) { $this->load->view($page); } else { show_404(); }
}
}
this controller would search for a template name equivalent to what you typed, i.e. if you are trying to reach pages/aboutus it would load the template from application/views/pages/aboutus.php
route:
$route['pages/(:any)'] = 'pages/index/$1';

- 5,350
- 2
- 26
- 48
-
the requirement is to change **cakephp/pages/1-page_title_here** to **cakephp/page_title_here**. – Kay Mar 01 '13 at 10:36
-
see edit. i see you already told another guy that won't work though? if you are loading pages from a database, then the easiest solution would be what i suggested before this i.e. urls like cakephp/pages/1-page_title_here or cakephp/pages/1/page_title_here. That is, unless you do like wordpress perhaps and compile a unique string with only a-Z0-9_ characters and append it to your page record in the database. Just make sure the mysql column is indexed or unique so that you don't run into conflicts and remain as efficient as using an ID. – skrilled Mar 01 '13 at 15:49
CakePHP has pretty rule to provide SEO-friendly URL without having to modify any essential codes. All you have to do is just put your view files inside your app/views/pages
folder.
For example if you have pages like 'home', 'about' and contact_us', just put 'home.ctp', 'about.ctp' and 'contact_us.ctp' inside pages folder.
So, the folder structure should goes like this:
/app/
/views/
/pages/
/home
/about
/contact_us
The URL structure to access your page should be like:
http://www.yourwebsite.com/pages/home
http://www.yourwebsite.com/pages/about
http://www.yourwebsite.com/pages/contact_us

- 1
- 2
-
this technique couldnt be implemented because my pages are dynamic. mysite.com/pages/1 gives about page and mysite.com/pages/2 gives services pages. and there can be many of those. – Kay Mar 01 '13 at 10:32
I think, it is more easy to solve using the extension for work with SEO. Try this Advanced SEO Suite http://mirasvit.com/magento-extensions/advanced-seo-suite.html

- 1