CodeIgniter:URL重写不起作用

时间:2014-09-29 14:39:43

标签: php .htaccess codeigniter mod-rewrite

我有一个使用CodeIgniter创建的网站,虽然URL重写正在我的本地安装(WAMP),但它在我的远程服务器上失败。

CI框架安装在“/ dev”文件夹中。

当我尝试使用以下网址访问控制器时出现以下错误:http://www.mywebsite.com/dev/controller

  

未找到

     

在此服务器上找不到请求的网址/dev/index.php/controller/。

我已经尝试过.htaccess和config.php的每个组合,但我无法弄清楚是什么问题。

然而,http://www.mywebsite.com/dev/效果很好。

这是.htaccess文件:

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

application / config / config.php文件:

$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'] = '';

真正奇怪的是,这个确切的配置曾经在另一台服务器上工作,我今天移动了我的代码,现在它不起作用......

有什么想法吗?

2 个答案:

答案 0 :(得分:1)

您在重写规则中未使用查询字符串,而是使用路径信息。尝试将uri协议更改为:

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

如果仍然无效,请尝试更改规则以附加查询字符串:

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

确保htaccess文件位于dev目录。

答案 1 :(得分:0)

试试吧

RewriteEngine On
RewriteBase /your_project_name/
RewriteCond %{REQUEST_URI} ^system.*
RewriteCond $1 !^(index\.php|images|js|uploads|css|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

和bingo