Welcome Guest, Not a member yet? Register   Sign In
How to Remove Index from URL
#1

[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.
#2

[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-gui...uting.html

e.g

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

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




Theme © iAndrew 2016 - Forum software by © MyBB