dongzi5673 2014-09-29 14:39
浏览 68
已采纳

CodeIgniter:URL重写不起作用

I have a website created with CodeIgniter, and although the URL Rewriting is working on my local installation (WAMP), it fails on my distant server.

The CI framework is installed in the "/dev" folder.

Here's the error when I try to access a controller using the following URL : http://www.mywebsite.com/dev/controller

Not Found

The requested URL /dev/index.php/controller/ was not found on this server.

I've tried every combination of .htaccess and config.php, but I can't figure out what's wrong.

However, http://www.mywebsite.com/dev/ works just fine.

Here's the .htaccess file :

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

And the application/config/config.php file :

$config['base_url']     = '/dev/'; # I tried to put the whole path, didn't work either
$config['index_page'] = '';
$config['uri_protocol'] = 'QUERY_STRING'; # I tried every possibility, none of them work
$config['url_suffix'] = '';

What's really weird is that this exact configuration used to work on another server, I moved my code today and it doesn't work now...

Any idea ?

  • 写回答

2条回答 默认 最新

  • dos71253 2014-09-29 14:43
    关注

    You're not using a query string in your rewrite rules, you're using path info. Try changing the uri protocol to:

    $config['uri_protocol'] = 'PATH_INFO';
    

    And if that still doesn't work, try changing your rules to append a query string instead:

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .* index.php?$0 [PT,L]
    #                       ^------ a "?" here instead of "/"
    

    And make sure the htaccess file is in the dev directory.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型