CodeIgniter:URL重写不起作用


CodeIgniter : URL rewriting not working

我有一个用CodeIgniter创建的网站,尽管URL重写在我的本地安装(WAMP)上工作,但它在我的远程服务器上失败了。

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

以下是我尝试使用以下URL访问控制器时的错误:http://www.mywebsite.com/dev/controller

未找到

在此服务器上找不到请求的URL/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'] = '';

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

知道吗?

您在重写规则中没有使用查询字符串,而是使用路径信息。尝试将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目录中。

试用

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]

和宾果