# CodeIgniter / .htaccess problems

**URL:** <https://forum.kirupa.com/t/codeigniter-htaccess-problems/262287>\
**Category:** programming\
**Created:** [June 4, 2008, 5:24pm UTC](https://forum.kirupa.com/t/codeigniter-htaccess-problems/262287 "2008-06-04T17:24:58Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![shane\_c](https://avatars.discourse-cdn.com/v4/letter/s/3be4f8/32.png) [@shane\_c](https://forum.kirupa.com/u/shane_c)\
**Post date:** [June 4, 2008, 5:24pm UTC](https://forum.kirupa.com/t/codeigniter-htaccess-problems/262287/1 "2008-06-04T17:24:58Z")

</div>

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/](http://example.com/blog/)’ rather than ‘[http://example.com/index.php/blog/](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:

```auto
<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:

```auto
$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!

---

<div class="post-metadata">

**Author:** ![simplistik](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/simplistik/32/7747_2.png) [@simplistik](https://forum.kirupa.com/u/simplistik)\
**Post date:** [June 4, 2008, 5:31pm UTC](https://forum.kirupa.com/t/codeigniter-htaccess-problems/262287/2 "2008-06-04T17:31:37Z")

</div>

```auto

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

```

instead of

```auto

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

```

---

<div class="post-metadata">

**Author:** ![shane\_c](https://avatars.discourse-cdn.com/v4/letter/s/3be4f8/32.png) [@shane\_c](https://forum.kirupa.com/u/shane_c)\
**Post date:** [June 4, 2008, 5:44pm UTC](https://forum.kirupa.com/t/codeigniter-htaccess-problems/262287/3 "2008-06-04T17:44:52Z")

</div>

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

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

```

it worked! Thanks simp 🍺

_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…

---

<div class="post-metadata">

**Author:** ![shane\_c](https://avatars.discourse-cdn.com/v4/letter/s/3be4f8/32.png) [@shane\_c](https://forum.kirupa.com/u/shane_c)\
**Post date:** [June 4, 2008, 9:10pm UTC](https://forum.kirupa.com/t/codeigniter-htaccess-problems/262287/4 "2008-06-04T21:10:24Z")

</div>

Well I basically got it working 🍺

```auto
# 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.

---

<div class="post-metadata">

**Author:** ![simplistik](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/simplistik/32/7747_2.png) [@simplistik](https://forum.kirupa.com/u/simplistik)\
**Post date:** [June 5, 2008, 1:16pm UTC](https://forum.kirupa.com/t/codeigniter-htaccess-problems/262287/5 "2008-06-05T13:16:54Z")

</div>

[QUOTE=shane-c;2336780]

```auto

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

```

[/QUOTE]

to make the trailing slash optional you’d do

```auto

^(.*)/?$

```

---

<div class="post-metadata">

**Author:** ![sekasi](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@sekasi](https://forum.kirupa.com/u/sekasi)\
**Post date:** [June 5, 2008, 1:29pm UTC](https://forum.kirupa.com/t/codeigniter-htaccess-problems/262287/6 "2008-06-05T13:29:38Z")

</div>

Oh, that’s really useful thanks simplistik.

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

---

<div class="post-metadata">

**Author:** ![shane\_c](https://avatars.discourse-cdn.com/v4/letter/s/3be4f8/32.png) [@shane\_c](https://forum.kirupa.com/u/shane_c)\
**Post date:** [June 5, 2008, 4:57pm UTC](https://forum.kirupa.com/t/codeigniter-htaccess-problems/262287/7 "2008-06-05T16:57:20Z")

</div>

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

```auto

^(.*)/?$

```

[/quote]

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