.htaccess - Removing index.php in Codeigniter 2 -
i'm having trouble using codeigniter2. want remove annoying "index.php" url that:
- http://localhost/ci_intro/index.php/site/home becomes - http://localhost/ci_intro/home
i've followed couple of links on stack overflow , have found following 2 posts:
remove index.php url - codeigniter 2
and
removing index.php codeigniter-2
however after performing both steps still no joy.
my .htaccess follows:
<ifmodule mod_rewrite.c> rewriteengine on rewritebase /ci_intro/ #removes access system folder users. #additionally allow create system.php controller, #previously not have been possible. #'system' can replaced if have renamed system folder. rewritecond %{request_uri} ^system.* rewriterule ^(.*)$ /ci_intro/index.php?/$1 [l] #when application folder isn't in system folder #this snippet prevents user access application folder #submitted by: fabdrol #rename 'application' applications folder name. rewritecond %{request_uri} ^application.* rewriterule ^(.*)$ /ci_intro/index.php?/$1 [l] #checks see if user attempting access valid file, #such image or css document, if isn't true sends #request index.php rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewriterule ^(.*)$ /ci_intro/index.php?/$1 [l] </ifmodule> <ifmodule !mod_rewrite.c> # if don't have mod_rewrite installed, 404's # can sent index.php, , works normal. # submitted by: elliothaughin errordocument 404 /index.php </ifmodule>
i've ensured mod_rewrite module enable in apache (i'm using xampp on windows) reason it's not working i'd expect to.
i have 2 views in codeigniter2, 1 called home , called about. these 2 link each other. links follows:
<a href="home">home</a><br/> <a href="about">about</a>
if go root url of project:
http://localhost/ci_intro/
the index function of home page displayed. that's fine , expected. however, if click either link redirects to:
http://localhost/ci_intro/home or http://localhost/ci_intro/about
which produces 404. if type "site" in url, name of controller, links take me through correctly loaded views:
http://localhost/ci_intro/site/home or http://localhost/ci_intro/site/about
is there known way of bypassing approach controller,in case site, removed url entirely using site/home or site/about in links in view not appear work?
you don't want (but might!).
- http://localhost/ci_intro/index.php/site/home becomes - http://localhost/ci_intro/home
the way ci works, site
controller , home
method or function in controller calling. allows gather respective functionality.
e.g. have home controller , index method like:
class home extends ci_controller{ public function index(){ echo 'i home controller index'; } }
which url http://example.com/home
(or http://example.com/index.php/home
before .htaccess involved) show page text "i home controller index".
then can add other functionality home controller a'la
class home extends ci_controller{ public function index(){ // http://example.com/home echo 'i home controller index'; } public function user(){ // http://example.com/home/user echo "i user method in home controller"; } }
which url http://example.com/home/user
show page text "i user method in home controller".
you can create many other controllers need:
class extends ci_controller{ public function index(){ // http://example.com/about echo 'i page!'; } }
http://example.com/about
render page text "i page!"
rewriteengine on rewritecond $1 !^(index\.php|images|robots\.txt) rewriterule ^(.*)$ index.php/$1 [l]
is .htaccess should need remove index.php form url. it'd live in /ci_into/.htaccess
if want use http://example.com/home works site controller, use routing