doulianxing4015 2014-02-04 15:28
浏览 97
已采纳

Codeigniter从URL中删除/index.php

Okay so I know that a lot of people have been asking the same or similar questions, but I don't seem to find a solution that works for my project. So please don't put this as a duplicate.

I have a website made with codeigniter. It was running just fine without the index.php in the url. So the rewrite was successfull. Until a few days ago: all of a sudden the admin area (/admin) returned a 404 and was only accessible by the path '/index.php/admin'. The rewrite code that once used to work didn't do a thing anymore.

And know I'm back at the start -> the problem is that I cannot delete the index.php from my url.

I tried so many things that I don't know what to do anymore.

The application is stored under 'public_html/application/... The image below is inside the application folder where the .htaccess file and index.php are. Is this the right location to change the .htaccess?

enter image description here

I tried rewriting the .htaccess but without success:

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

RewriteEngine on
RewriteCond $1 !^(index\.php|public|\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^CI/(index\.php|public|images|robots\.txt|css)
RewriteRule ^(.*)$ /index.php/$1 [L]

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots|css\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

My config file:

$config['base_url'] = 'http://www.mysite.be/';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';

Routes.php:

$route['default_controller'] = "c_home/index";
$route['404_override'] = '';
$route['admin'] = "c_home/adminpanel";
$route['logout'] = "c_login/logout";

Does anybody have a clue what is going on or how this can be fixed?

Thanks in advance!

  • 写回答

5条回答 默认 最新

  • dongzi0857 2014-02-26 19:49
    关注

    So I have been messing around with this and finally made it work

    For this I made changes to the htaccess and controllers.
    I changed the admin function to a new controller and changed this in the routes.php

    new routing

    $route['admin'] = "c_login/index";
    

    new .htaccess

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .* index.php/$0 [PT,L] 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?