首页 文章

CodeIgniter:URL重写不起作用

提问于
浏览
0

我有一个使用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'] = '';

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

任何的想法 ?

2 回答

  • 0

    你're not using a query string in your rewrite rules, you'正在使用 path info . 尝试将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

    试试吧

    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]
    

    和宾果游戏

相关问题