CodeIgniter Forums
Remove controller name from url - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Remove controller name from url (/showthread.php?tid=3410)



Remove controller name from url - El Forum - 09-29-2007

[eluser]Giacomo[/eluser]
Hi everybody,
since I have just one controller, I would like to remove the controller name from url.

Instead this:
domain . com / index.php / welcome / function_name

Something like this:
domain . com / index.php / function_name

Is it possible?

Bye and thanks


Remove controller name from url - El Forum - 09-29-2007

[eluser]Kemik[/eluser]
I suppose you could using routing.


Remove controller name from url - El Forum - 09-29-2007

[eluser]garymardell[/eluser]
nah wouldnt work, you can change the welcome to say something else using routing but it would still have to be there.
If you have 2 functions in 2 different controllers then which one would get used? CI needs to be told which controller to call and use what you want gives no indication of which one.

Unless you were to do everything in one controller and use htaccess (maybe) to remove the first url segment.

Is it really important that you remove the controller name?


Remove controller name from url - El Forum - 09-29-2007

[eluser]Giacomo[/eluser]
[quote author="gazza" date="1191089363"]nah wouldnt work, you can change the welcome to say something else using routing but it would still have to be there.
If you have 2 functions in 2 different controllers then which one would get used? CI needs to be told which controller to call and use what you want gives no indication of which one.

Unless you were to do everything in one controller and use htaccess (maybe) to remove the first url segment.

Is it really important that you remove the controller name?[/quote]
No, it's not too much important. If it would have been possible...Smile


Remove controller name from url - El Forum - 09-29-2007

[eluser]xwero[/eluser]
It's possible in your scenario where you only have one controller to use routing. If you have several controllers you can do it too if your function names are unique.


Remove controller name from url - El Forum - 09-29-2007

[eluser]imzyos[/eluser]
if, you want security, you could use _remap controller function to switch between all controllers


Remove controller name from url - El Forum - 09-30-2007

[eluser]Matthew Pennell[/eluser]
[quote author="Giacomo" date="1191081377"]Hi everybody,
since I have just one controller, I would like to remove the controller name from url.

Instead this:
domain . com / index.php / welcome / function_name

Something like this:
domain . com / index.php / function_name

Is it possible?[/quote]

Code:
$routes['([a-z\_]+)$'] = "welcome/$1";



Remove controller name from url - El Forum - 09-30-2007

[eluser]imzyos[/eluser]
i must learn RegEx ¬¬


Remove controller name from url - El Forum - 09-30-2007

[eluser]Giacomo[/eluser]
[quote author="Buddy Bradley" date="1191151815"]
Code:
$routes['([a-z\_]+)$'] = "welcome/$1";
[/quote]
Thanks to everybody...=)


Remove controller name from url - El Forum - 09-30-2007

[eluser]Giacomo[/eluser]
[quote author="Buddy Bradley" date="1191151815"]
Code:
$routes['([a-z\_]+)$'] = "welcome/$1";
[/quote]
Just another question: what about if i want to match all except one string?

I tried with:
Code:
$routes['([a-z\_]+)^string$'] = "welcome/$1";
But it doesn't work.