Welcome Guest, Not a member yet? Register   Sign In
How to display site homepage using http://localhost/ci instead of http://localhost/ci/welcome
#1

[eluser]developer86[/eluser]
Hello good people,

I am new to codeigniter and i'm urgently looking for help with loading a website homepage without entering any controller name in my URL input.

For example, when i enter http://localhost/ci/ in my web browser, i want to see the homepage (main page) loaded at http://localhost/ci/welcome but instead it returns all directories in the index of /ci. This is the problem i have and i've been trying hard to resolve it without any luck.

Currently, i'm able to successfully load the homepage URL with any of the options below:

http://localhost/ci/welcome
http://localhost/ci/welcome/index
http://localhost/ci/index.php


Please refer to the steps below that i took to remove index.php from my URLs

1. Config file (application/config/config.php) edited to show the following;

Code:
$config['base_url'] = '';
Code:
$config['index_page'] = '';

2. application/config/routes.php still points to welcome controller

Code:
$route['default_controller'] = "welcome";

3. created a .htaccess file with the following rules;

Code:
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /ci/

    #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]

    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Submitted by: Fabdrol
    #Rename 'application' to your applications folder name.
    RewriteCond %{REQUEST_URI} ^application.*
    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
    RewriteCond $1 !^(index\.php|css|images|robots\.txt)
    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>


Please help me fix this
#2

[eluser]Karman de Lange[/eluser]
Is your web server setup to run index.php as default document?

see : http://stackoverflow.com/questions/23844...by-default
#3

[eluser]Tpojka[/eluser]
Try this one.
#4

[eluser]developer86[/eluser]
[quote author="Karman de Lange" date="1387802968"]Is your web server setup to run index.php as default document?

see : http://stackoverflow.com/questions/23844...by-default[/quote]

Hi Karman, thank you for your post.

index.php was not setup as the default document in my web server (Apache 2.4.7).
Instead, index.html was setup in the server configuration file httpd.conf by default.
.
After adding index.php to my .htaccess file, i successfully launched my home page at http://localhost/ci.
The updated .htaccess file now contains the following line at the top and the rest of its contents are the same;

Code:
DirectoryIndex index.php

I really appreciate your support and direction. Everything is working according to my expectations !
#5

[eluser]developer86[/eluser]
[quote author="Tpojka" date="1387803559"]Try this one.[/quote]

Thanks for the link. I found it useful but i already got a solution to the same problem.
#6

[eluser]Tpojka[/eluser]
Also, regarding user guide, you should make this change too:
Code:
$config['base_url'] = 'http://localhost/ci/';
#7

[eluser]developer86[/eluser]
[quote author="Tpojka" date="1387930206"]Also, regarding user guide, you should make this change too:
Code:
$config['base_url'] = 'http://localhost/ci/';
[/quote]

Is it a best practice rule ? My understanding has been that if base_url is not set, codeigniter will automatically find it. Otherwise, i have set it up now. Thanks again for your support.
#8

[eluser]Tpojka[/eluser]
I am setting base URL all the time. And don't forget trailing slash on it because of future code collision.
CI is meant to use it with trailing slash set - there is explanation in config.php too.
#9

[eluser]developer86[/eluser]
Ok, thanks. I have done the same.




Theme © iAndrew 2016 - Forum software by © MyBB