CodeIgniter Forums
Remove index.php and call default controller method when page loads - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Remove index.php and call default controller method when page loads (/showthread.php?tid=33245)



Remove index.php and call default controller method when page loads - El Forum - 08-19-2010

[eluser]fiktionvt[/eluser]
I am kind of new to setting up a new page in codeigniter. say my page domain is www.example.com

I have a controller called Site, with two methods index(), and home(). When I navigate to www.example.com I want it to call the Site.php controller. It can either call index() or home() it doesn't really matter but I want the url to either display www.example.com or www.example.com/home

I know this is very basic but for some reason I can't find how to set this up. Right now when the page loads it somehow finds the Site controller and is calling the index function, I am not sure how it is doing that.

Anyway if someone can tell me how to properly do this that would be great. Thanks for any help!

-Fik


Remove index.php and call default controller method when page loads - El Forum - 08-19-2010

[eluser]fiktionvt[/eluser]
Sorry to be clear I want my base url of my site to point to www.example.com/index.php/Site/ so when I goto the url www.example.com it is actually is www.example.com/index.php/Site but displays www.example.com

sorry if this is confusing


Remove index.php and call default controller method when page loads - El Forum - 08-19-2010

[eluser]CroNiX[/eluser]
In config/routes.php, change the "default controller" to "site".

Then whenever anyone visits your domain with no path (www.example.com), it will load the index method of the class site. (www.example.com/site) but only display the domain.

As far as getting rid of index.php, this .htaccess rule (in your sites root dir) usually does the trick:
Code:
RewriteEngine On

# Handle the index.php file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]