0

我在 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 的情况下工作,如果你能解释我所缺少的,请给我解释。

4

1 回答 1

1

一般来说,Codeigniter 在调用其主根目录时倾向于显式隐藏 index.php,但是当您尝试直接在 url 中访问其子文件夹时,需要 index.php。为了做到这一点,您必须在其中包含一个 .htaccess ci 文件系统,将接受使用 domain/product 或 domain/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>  
于 2013-03-22T01:42:18.193 回答