Codeigniter issues with paths in localhost (XAMPP)

丶灬走出姿态 提交于 2019-12-09 03:20:06

问题


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:

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:

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

displaying:

I have controllers setup like:

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?


回答1:


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.



回答2:


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 :)



来源:https://stackoverflow.com/questions/13146395/codeigniter-issues-with-paths-in-localhost-xampp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!