2

The index page (aka homepage.php) in my code igniter install is working fine no matter what.

The problem lies with using subdirectories to store other pages, currently its setup like: img1

loading homepage like http://localhost/VAw_CI/ works fine (loading homepage.php), this is setup in routes.php:

$route['default_controller'] = "pages/homepage";

in config.php, I've setup:

$config['base_url'] = 'http://localhost/VAw_CI';

/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
|
| Typically this will be your index.php file, unless you've renamed it to
| something else. If you are using mod_rewrite to remove the page set this
| variable so that it is blank.
|
*/
$config['index_page'] = '';

I specified $config['index_page'] = ''; above, because I modified my .htaccess located in htdocslike:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .*homepage/$0 [PT,L]

However, if I try to login on homepage.php, which is currently looks like: img2

It sends me to http://localhost/VAw_CI/pages/clientlogin

displaying: img3

I have controllers setup like: img4

What gives here? When I visit http://localhost/VAw_CI, it is effectively loading the views->pages->homepage.php view properly, but it seems any other view doesn't work am I missing some path setup somewhere for pages other than the index (homepage.php) in my case?

2
  • 2
    I think you're mistaking controllers with views..."pages" are (usually) controllers, which in turn call views to render their output. I suggest reading CI manual and/or something about MVC Commented Oct 30, 2012 at 19:43
  • I used the pages/ dir as a subdir in both /controllers/pages and views/pages as a way to categorize Commented Oct 30, 2012 at 19:51

2 Answers 2

6

please create .htaccess file in project folder and write:

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL
RewriteRule ^(.*)$ index.php?url=$1 [PT,L] 

</IfModule>
<IfModule !mod_rewrite.c>
 ErrorDocument 404 index.php
</IfModule>

You don't need to define in base_url in config file:

$config['base_url'] = ''; // blank it.
Sign up to request clarification or add additional context in comments.

4 Comments

Thank you! I thought this was included by default. It isn't. ellislab.com/codeigniter/user-guide/general/urls.html
Yes, @MarcoW. It is included. But here i've give a answer of the question...:)
you solved a problem chatGPT refused to solve in 2days. Thanks. Im new to codeIgniter though.
@dataplace : happy that works, However this answer is decade ago! so bit surprised. ANyway i'm still using CI! If any help let me know :)
0

Figured out what I was doing wrong:

I needed to be accessing : http://localhost/VAw_CI/**index.php**/pages/aboutus which is really strange because my default CI page is set to $config['index_page'] = 'homepage';

Hope this helps someone, sometime :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.