0

My current url is

baseUrl/categories/category/categoryName/subcatName...

To convert this url into

baseUrl/categoryName/subcatName...

i am using following route

Router::connect(
    '/:slug/*',
    array(
        'controller' => 'Categories',
        'action' => 'category'
    ),
    array(
        'pass' => array('slug'),
        'slug'=>'[a-zA-Z]+'
    )
);

but it is creating problem with urls like:

baseUrl/home
baseUrl/myaccount ..
etc.

and redirect them to category action.

ndm
  • 59,784
  • 9
  • 71
  • 110
  • 1
    Not much of a surprise - if you want a catchall route like that the simplest solution is to declare all your other routes _first_. – AD7six Jul 04 '15 at 14:12

1 Answers1

0

The common solution to this problem is to add a single letter (like Reddit).

baseUrl/r/slug/something-awesome

That way, you can make the route:

Router::connect(
'/r/:slug/*',
array(
    'controller' => 'Categories',
    'action' => 'category'
),
array(
    'pass' => array('slug'),
    'slug'=>'[a-zA-Z]+'
)
);
Dave
  • 28,833
  • 23
  • 113
  • 183