views:

59

answers:

1

Hello all,

I am making use of Codeigniter and I currently have this URL format setup:

http://example.com/view/

I would like to put in the logged in users username in the URL and remove the view part of the URL. The view is my controller. So I can have something that looks like this in the address bar:

http://example.com/johnny

However, I firstly tried removing the view part using my htaccess file like so:

RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|images|css|js|swfupload|uploads|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA]

#trying to remove view??
RewriteRule ^(.*)$ view.php/$1 [QSA]

But this resulted in a 403 (forbidden) error as I have just corrupted the URL requested!

How can I best achieve this? Maybe making use of Codeigniter's routes?

Thank you all for any help.

+4  A: 

You basically have to make a route and then routes for everything else thats not for profiles. Its kind of annoying but thats how you have to do it in CI, I may be wrong. For example:

$route['user/login'] = "user/login"
$route[':any'] = "profile/$1"; // user profile
mikelbring
Would I be able to add the URLs logged in name in the routes file? i.e.`$username = $this->session->userdata('username'); $route['view/'.$username] = "view/index/$1";` ??
Abs
@Abs No, but why would you need to?
mikelbring