pinaldesai
pinaldesai

Reputation: 1815

Routes in Codeigniter

I want to have a clean URL in CodeIgniter based application for User's Profile Information.

Please Take a look at URL formats below.

Actual URL : http://www.mydomain.com/index.php/users/profile/user1

I'm expecting users to have Personal URL's like

http://www.mydomain.com/user1
http://www.mydomain.com/user2
http://www.mydomain.com/user3

URL http://www.mydomain.com/user1 should process http://www.mydomain.com/index.php/users/profile/user1 in background execution.

I will be removing index.php from URL using Route library.

Thanks in advance for any sort of help.

Upvotes: 6

Views: 382

Answers (2)

Andreas Bergström
Andreas Bergström

Reputation: 14610

Have a look at https://www.codeigniter.com/user_guide/general/routing.html.

$route['user(:num)'] = "users/profile/user/$1";

If you mean you want /anyusername to route to the users controller, you would have to put:

$route['(:any)'] = "users/profile/$1";

At the bottom of routes.php and every non user-URL above it. Otherwise every URL would be routed there, obviously. You will need to implement some mechanism in the users-controller to throw 404-errors, since you are routing all requests not catched in the routing rules above.

Upvotes: 10

Pramod Kumar Sharma
Pramod Kumar Sharma

Reputation: 8012

IN config/routes.php

add this line

$route['user(:num)'] = "users/profile/$1";

Upvotes: 1

Related Questions