CodeIgniter / .htaccess problems

I’m trying to remove ‘index.php’ from my URI, but I can’t seem to get it to work.

i.e. I want it to read ‘http://example.com/blog/’ rather than ‘http://example.com/index.php/blog/

Can anybody please let me know what I’m doing wrong?

My .htaccess file is in my site’s root (as is my CI installation). I got this from the CI wiki:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule>

And I also changed my system/application/config/config.php so that the ‘index_page’ line says:

$config['index_page'] = '';

But it’s still not working - I still need to include /index.php/ in the URI for it to work properly. What am I missing? Thanks in advance for any help!


RewriteRule ^(.*)$ /$1 [L]

instead of


RewriteRule ^(.*)$ /index.php/$1 [L]

Well, that gave me an error, but it did get me on track to changing that line… And when I tried changing it to

RewriteRule ^([a-zA-Z0-9\-]+)/?$ index.php/$1 [L,QSA]

it worked! Thanks simp :beer:

EDIT BAH! Nevermind, it didn’t work so hot… When I try passing a function name after that it doesn’t work. I wish I understood this htaccess stuff better…

Well I basically got it working :beer:

# this is the initialization
Options     +FollowSymLinks
RewriteEngine     On
RewriteBase     /
# these are the rewrite conditions
RewriteCond     %{REQUEST_FILENAME}     !-f
RewriteCond     %{REQUEST_FILENAME}     !-d
# and finally, the rewrite rules
RewriteRule     ^(.*)/$    index.php/$1 [L]

The only problem I’m still having is when I leave out the trailing slash, it doesn’t work. I’m not too worried about it, but it is kind of annoying.

[QUOTE=shane-c;2336780]


RewriteRule     ^(.*)/$    index.php/$1 [L]

[/QUOTE]

to make the trailing slash optional you’d do


^(.*)/?$

Oh, that’s really useful thanks simplistik.

I’ve been doing 2 Redirectmatches/RewriteRules for directories with and without trailing slashes. But no more! :slight_smile:

[quote=simplistik;2337220]to make the trailing slash optional you’d do


^(.*)/?$

[/quote]

I actually already tried that, and for some reason it made the whole thing not work. Very odd.