Welcome Guest, Not a member yet? Register   Sign In
how to make URL friendly like http://mywebsite/username
#1

[eluser]Linh Pham[/eluser]
Hi there,
pelese help me, how to custom the URL of CodeIgniter like
http://mywebsite.com/users/username
becomes
http://mywebsite.com/username
#2

[eluser]Samus[/eluser]
[quote author="Linh Pham" date="1334249752"]Hi there,
pelese help me, how to custom the URL of CodeIgniter like
http://mywebsite.com/users/username
becomes
http://mywebsite.com/username[/quote]
routes

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

http://ellislab.com/codeigniter/user-gui...uting.html
#3

[eluser]RiccardoC[/eluser]
[quote author="Samus" date="1334250559"][quote author="Linh Pham" date="1334249752"]Hi there,
pelese help me, how to custom the URL of CodeIgniter like
http://mywebsite.com/users/username
becomes
http://mywebsite.com/username[/quote]
routes

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

http://ellislab.com/codeigniter/user-gui...uting.html[/quote]
This will change ALL uri to http//mywebsite.com/users/xxxx
To change only what the user asked
Code:
$route['username/(:any)'] = "users/username/$1";
Otherwise another call like http://mywebsite/another_controller/method/ will be routed to http://mywebsite/users/another_controller/method/
#4

[eluser]Samus[/eluser]
[quote author="RiccardoC" date="1334253859"][quote author="Samus" date="1334250559"][quote author="Linh Pham" date="1334249752"]Hi there,
pelese help me, how to custom the URL of CodeIgniter like
http://mywebsite.com/users/username
becomes
http://mywebsite.com/username[/quote]
routes

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

http://ellislab.com/codeigniter/user-gui...uting.html[/quote]
This will change ALL uri to http//mywebsite.com/users/xxxx
[/quote]
That's what he asked for..

Although your approach is what would be recommended.
#5

[eluser]CroNiX[/eluser]
If you don't want the controller/method in the url (like the op stated, he only wants the actual username, not "username") then you have to use a catch all route like Samus wrote in his first post. Riccardo is also correct that it will route everything to that controller. If the OP doesn't want that then he would have to create additional routes for all of his other controllers before the catch-all route. It's redundant, but what you have to do in order to have controllerless/methodless URLs.
#6

[eluser]Linh Pham[/eluser]
Hi there,
thank you all for the answers, but my website is still not doing fine after change.
i meant have a url friendly like example http://www.facebook.com/phamhuulinh
to make this ,must i custom the .httaccess?
one more thing, the structure my web using :
controller/method/id ( http://domainname.com/users/viewprofile/123 )
and i want it will become http://domainname.com/phamhuulinh ( of course phamhuulinh is alias of id 123)
#7

[eluser]CroNiX[/eluser]
Yes, you'd need to remove index.php from the url via htaccess as described in the user guide in the CodeIgniter URLs section and also set 'index_page' to an empty string in the config.

To test to see if your route is working without removing index.php, try:
www.yoursite.com/index.php/username
#8

[eluser]Linh Pham[/eluser]
[quote author="CroNiX" date="1334281569"]Yes, you'd need to remove index.php from the url via htaccess as described in the user guide in the CodeIgniter URLs section and also set 'index_page' to an empty string in the config.

To test to see if your route is working without removing index.php, try:
www.yoursite.com/index.php/username[/quote]

i removed before that, currently my URL is http://domainname.com/users/viewprofile/123
ID 123 and username is phamhuulinh
when making it become http://domainname.com/phamhuulinh , this case framework will be understanding phamhuulinh is a controller, still does not work
#9

[eluser]CroNiX[/eluser]
What route did you create?
#10

[eluser]Linh Pham[/eluser]
[quote author="CroNiX" date="1334282018"]What route did you create?[/quote]
how to create?
i tried a few replies above., but did not work,
have you suggestion




Theme © iAndrew 2016 - Forum software by © MyBB