普通网友 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 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误