CodeIgniter不使用子文件夹

时间:2013-03-22 01:32:59

标签: codeigniter codeigniter-2

我在web根目录中有我的codeigniter代码。 mod_rewrite已启用..我通过phpinfo.php检查。现在代码结构是这样的

  controllers/home.php(default controller)
  controllers/products.php (not listed in routes.php under config)
  and then a subfolder
  controllers/members/login.php

我正在尝试的网址是

 domain_name/ ---------> works
  

(注意:这是我的echo base_url指向我的地方   因为$ config ['index.php'] ='',但即使将其设置为index.php也是如此   没有把我指向工作index.php url)

  domain_name/products ------> doesn't work
    domain_name/index.php/products ------> works
    similarly 
    domain_name/members ----->doesn't work
    domain_name/index.php/members --->work

因为这个东西正在使用index.php我猜测routes.php工作正常。但有些echo $ base_url指向我没有index.php网址的那些。

我已经尝试了我的webroot中的.htacess文件,它是/ var / www /    codeigniter的版本是2.1.3

请帮忙。我希望这可以使用或不使用index.php,如果你能解释我所缺少的内容,请给我解释。

1 个答案:

答案 0 :(得分:0)

一般来说Codeigniter倾向于明确隐藏index.php,当调用它的主根时,但是当你试图直接在url中访问它的子文件夹时.. index.php是必需的。为了做到这一点你必须包含一个。您的ci文件系统中的htaccess将接受使用域/产品或域/ index.php / product

因此,请尝试包含此.htacess并将其重写基础更改为您的ci文件夹名称

 <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /cifolder

    #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>