• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to use .htaccess with code igniter

#1
[eluser]Unknown[/eluser]
i have downloaded CI 1.7 and extract in my root. my project named hello_world. here is my .htaccess file and it's location is /hello_world/.htaccess
Code:
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
i write a simple controller named home
Code:
class Home extends Controller {
    function __construct()
    {
        parent::Controller();    
    }
    function test_func()
    {
        echo 'test_func';
    }
}
i am trying to access
Code:
http://localhost/hello_world/home/test_func
but it shows me output of http://localhost/ (wamp home page)
and when i add index.php as
Code:
http://localhost/hello_world/index.php/home/test_func
it works fine.
what changes needed in .htaccess file?
FYI: my mod_rewrite is on and i am using WampServer Version 2.0. in addition i have not changed index.php file location.
thanks in advance

#2
[eluser]Sumon[/eluser]
change .htaccess to
Code:
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /hellow_world/index.php/$1 [L]
</IfModule>

#3
[eluser]mattthehoople[/eluser]
RewriteEngine on
RewriteRule ^(home|controller2|controller3|etc)/?(.*) index.php/$1/$2

#4
[eluser]mattthehoople[/eluser]
...or you could exclude any files you don't want rewritten (including index.php) and do the rest

RewriteEngine on

RewriteRule ^(js|css|flash|includes|index.php) - [L]
RewriteRule ^(.*) index.php/$1 [L]


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.