Codeigniter - >得到404错误。简单的路线不起作用

时间:2010-12-15 18:58:32

标签: php codeigniter

我是一个asp.net家伙,这是我第一次处理PHP。

无论如何,我一直在努力将现有网站迁移到新服务器。

此网站正在使用codeigniter。

当我致电http://mydomain/admin时 我收到了404错误!

但如果我打电话:

http://mydomain/index.php/admin

它有效!

我在根目录下放了一个.htaccess文件:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|stylesheets|scripts|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

我已在config.php中设置:

$config['index_page'] = '';

我的routes.php:

$route['default_controller'] = 'welcome';
$route['scaffolding_trigger'] = '';

我不知道它为什么不起作用。我想它一定是非常简单的......

谢谢!

6 个答案:

答案 0 :(得分:6)

你看过这个吗?: http://codeigniter.com/wiki/mod_rewrite/

如果没有,试试这个:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Submitted by: Fabdrol
    #Rename 'application' to your applications folder name.
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule> 

曾经有一个来自Jamie Rumbelow我常常使用它,但它不再在他的博客上......我现在习惯了nginx,所以我最喜欢的配置对你不起作用。

答案 1 :(得分:2)

你的.htaccess文件对我来说也不起作用。但是,一旦我将重写规则改为此,它就起作用了:

RewriteRule ^(.*)$ index.php/$1 [L]

我刚开始删除了斜杠。

答案 2 :(得分:1)

试试这个:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule .* index.php/$0 [PT,L]

答案 3 :(得分:1)

- 在根目录中创建一个.htaccess文件,即CodeIgniter项目。

- 在创建的.htaccess文件中输入代码:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule .* index.php/$0 [PT,L]

答案 4 :(得分:0)

尝试在.htaccess

中添加RewriteBase /

答案 5 :(得分:0)

            $default_controller = "home";
            $language_alias = array('gr','fr');
            $controller_exceptions = array('signup');
            $route['default_controller'] = $default_controller;
            $route["^(".implode('|', $language_alias).")/(".implode('|', $controller_exceptions).")(.*)"] = '$2';
            $route["^(".implode('|', $language_alias).")?/(.*)"] = $default_controller.'/$2';
            $route["^((?!\b".implode('\b|\b', $controller_exceptions)."\b).*)$"] = $default_controller.'/$1';
            foreach($language_alias as $language)
            $route[$language] = $default_controller.'/index';
            $route['404_override'] = '';