普通网友 2016-07-03 12:37
浏览 38
已采纳

CodeIgniter路由或.htaccess问题

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 : www.example.com, 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 www.localhost.com/project 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 127.0.0.1/project/admin it gows to 127.0.0.1/project/admin/admin/login 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 127.0.0.1/admin/admin/ login and of course it goes 404 on me, but if I specify: 127.0.0.1/project/admin/login than it loads what you see in the picture above.

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

Routes:

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

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

//admin
$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";
  • 写回答

1条回答 默认 最新

  • douti6740 2016-07-03 15:19
    关注

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

    to

    $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 /
    

    to

    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: my-domain.com.local and using your hosts file for connecting this domain through localhost 127.0.0.1 my-domain.com.local

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算