0

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?

Kay
  • 498
  • 3
  • 14
  • See this question: https://stackoverflow.com/questions/48146369/how-to-make-cakephp-3-url-ready-for-marketing/48146522?noredirect=1#comment83271197_48146522 – lechat Jan 15 '18 at 05:03

3 Answers3

0

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';
skrilled
  • 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
0

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

Abed
  • 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
0

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

Vik
  • 1