PhpJunior PhpJunior - 11 months ago 90
PHP Question

CodeIgniter routing or .htaccess issue

I just got a new CodeIgniter project and I think I have either routing problems or a .htaccess problem, the situation is like this:

The project is on a domain like this :, and of course I need a copy of it in my /var/www/html/project folder because I don't want to work directly on the production server.

So I downloaded it and managed to get the front end part working perfectly from my localhost/project folder (actually I ended up using the ip address because if I use localhost it gows to for some reason eventhough I edited the htacces file, but i can work with the ip).

Now the thing is something really weird is going in the back office part, I mean if I type it gows to insteand of /admin/login.

And the links to all the css and js files are weird and can't figure out where this weirdness comes from.

Here are some pics:

Weird css loading

So as you can see in the picture above in the code it looks ok that's the path to the folder css/admin.css which is correct, but if you look in the console you can see that it tries to load admin/css/admin.css which of course it's not ok.

Now when I type in the adress bar : 1270.0.0.1/project/admin it goes to login and of course it goes 404 on me, but if I specify: than it loads what you see in the picture above.

Below I will put the routes and stuff from the config file:


$route['default_controller'] = "home";
$route['scaffolding_trigger'] = "";

$lang = "([a-zA-Z]{2}/)?";
$index_lang = "([a-zA-Z]{2}/?)?";

$route["admin"] = "admin";
$route["admin/(.*)"] = "admin/$1";

From the config:
$config['base_url'] = "";
$config['admin_url'] = $config['base_url']."admin/";
$config['base_path'] = $_SERVER['DOCUMENT_ROOT']."/project/";

| 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'] = "index.php";


I have worked with CodeIgniter just a few times, but I think the cause of your problem is a) using relative paths or b) bad URL configuration

try to rewrite in config

$config['base_url']     = "";


$config['base_url']     = "http://localhost-or-ip/project-folder-name/";

another solution can be modifing your .htaccess file in root directory - and of course modify your config.php to $config['base_path'] = $_SERVER['DOCUMENT_ROOT']; (or another original value) you can try in .htacces rewrite this:

RewriteBase /


RewriteBase /project-folder-name/

both solutions(if they will work) are useable, but you should consider using Virtual Hosts and set your localhost domain url for example as: and using your hosts file for connecting this domain through localhost