CodeIgniter Forums
I want to use username on my url, how can i ? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: I want to use username on my url, how can i ? (/showthread.php?tid=49003)



I want to use username on my url, how can i ? - El Forum - 02-05-2012

[eluser]Unknown[/eluser]
hello all

I am a new study of CI and I want to use username on my url like

http://localhost/mywebsite/charler

and make a mod rewrite to http://localhost/mywebsite/user/getuser/charler
after I study how to remove index.php with create a .htaccess file like

Code:
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /mywebsite/index.php/$1 [L]

so I modify a little bit to
Code:
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /mywebsite/index.php/user/getuser/$1 [L]

It doesn't work just give me 404.
Then I replace [L] with [R, L], It's work but i don't want it that way. I'm very confusing right now. I just want to know why and how I can get what I want.

thanks in advance.
sorry for my bad english.


I want to use username on my url, how can i ? - El Forum - 02-05-2012

[eluser]vbsaltydog[/eluser]
http://ellislab.com/codeigniter/user-guide/general/routing.html


I want to use username on my url, how can i ? - El Forum - 02-05-2012

[eluser]Unknown[/eluser]
wow ... Interesting It's work !!!!
don't change .htaccess just change route[404]

Code:
$route['404_override'] = 'user/getuser';

and use
Code:
$this->uri->segment(1)
to retrieve username

I spent almost two days to figure it out.

Thank you very much, vbsaltydog


I want to use username on my url, how can i ? - El Forum - 02-06-2012

[eluser]Aken[/eluser]
404_override is the route for what controller/method should be displayed in the event of a 404. Change this route to a specific method meant to display a 404 error. Add a new route for your usernames.