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 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 arduino控制ps2手柄一直报错
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题