1

Assume base_url is "http://www.facebook.com"

Default controller is "Home"

How do i code my routes and controller to get my URL as "http://www.facebook.com/noddycha"

Where "noddycha" is a get parameter. The page should load my profile page from DB.

2

1 Answer 1

0

In your application/routes.php file add this line after $route['404_override'] = '';:

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

Now absolutely everything will be redirected the profile function of the users controller (or whichever controller/function combination you substituted in the routes.php file). Then you can get the parameter by doing this in the profile function:

if ($this->uri->total_segments() === 1) {
    $profile = $this->uri->segment(1);
}

If you have some other controllers which you would still like to be able to access, e.g. an about us page, add them after the above line in the routes.php file. For example, if we extend the example above:

$route['(:any)'] = 'users/profile';
$route['home/about'] = 'home/about_us';

Would mean that every request is sent to the users/profile function, except http://example.com/home/about will go to the about us page.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.