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 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考