CodeIgniter Forums
How to Remove Index from URL - 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: How to Remove Index from URL (/showthread.php?tid=51146)



How to Remove Index from URL - El Forum - 04-22-2012

[eluser]pdxbenjamin[/eluser]
Yes yes, I know how to remove it from the root directory using .htaccess that works fine.
Code:
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]
    
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

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

RewriteCond %{ENV:REDIRECT_SUBDOMAIN} =""
RewriteCond %{HTTP_HOST} ^([a-z0-9][-a-z0-9]+)\.site\.com\.?(:80)?$ [NC]
RewriteCond %{DOCUMENT_ROOT}/%1 -d
RewriteRule ^(.*) %1/$1 [E=SUBDOMAIN:%1,L]
RewriteRule ^ - [E=SUBDOMAIN:%{ENV:REDIRECT_SUBDOMAIN},L]

</IfModule>

<IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php
</IfModule>


However, I've created a new folder in my views /views/roll/
I'm trying to organize my code a bit better in folders.

In the controller called roll.php i've made a few functions starting out with index().
I'm trying to grab the username ie, http://site.com/roll/jdoe

Code:
function index()
{
     $segment = $this->uri->segment(3);
     $data['main_content'] = 'roll/roll';
     $this->load->view('includes/templateroll', $data);
}

But, to do that the url is http://site.com/roll/index/jdoe
How do I get the .htaccess to remove that INDEX?

Thanks.



How to Remove Index from URL - El Forum - 04-22-2012

[eluser]Samus[/eluser]
You don't.

index is a method in your controller so it is displayed as every other url is.

siteurl.com/controller/method/param1/param2

If you don't want the index to appear in your url use routes.

http://ellislab.com/codeigniter/user-guide/general/routing.html

e.g

Code:
$route['roll/(:any)'] = "roll/index/$1";



How to Remove Index from URL - El Forum - 04-22-2012

[eluser]pdxbenjamin[/eluser]
Ahhhhhh Thank you. I always forget about Routes