avoid having 'index' in url when using a variable in cakephp

When you want to have a link like


In Cakephp you have to rewrite it to:


If you don't do this cakephp complains that within the users controller there is no action called 54. Is there no other way around this? Like to tell cakephp that when the second variable in the url is a number (so in this case 54), to refer it to the index function:

public function index($userId = null).

I hope this makes sense
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bernard S.CTOCommented:
You might consider doing a mod_rewrite within your htaccess, ie by Apache outside of php itself
ioboxWeb ArchitectCommented:
You should consider start using routes:

Routes and Connected Params

You'll need to create a route that will match your pattern.

http://www.domain.com/users/index/54/John -> This is the default pattern: domain/controller/action/param1/param2/etc...

Open the file /app/Config/routes.php and create at the very top a route that will match your pattern in this way (routes are matched top to bottom)

    array('controller' => 'users', 'action' => 'index'),
         'pass' => array('id', 'slug'),
         'id' => '[0-9]+'

Open in new window

Router::connect in quick:
- Param1: Url to match (/users/:id/:slug),
- Param2: Where the request must be dispatched (controller users, action index)
- Param3: Passed parameters and validation (we pass the id and slug from first param and then validate the param id to make sure it contains only numbers)

Hope it helps.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bernard S.CTOCommented:
Iobox's answer is highly to the point
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.