【问题标题】:Remove index.php from CodeIgniter从 CodeIgniter 中删除 index.php
【发布时间】:2014-09-20 21:37:12
【问题描述】:

我使用 CodeIgniter 2.2.0 和 AppServ 2.5.10 作为本地服务器。 在 config.php 我确定来自: $config['index_page'] = ''; 这是根文件夹中的 .htaccess(护理):

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /nursing/

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

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

当我尝试访问:localhost/nursing/welcome/index 时,AppServ 欢迎页面出现了!,而不是应有的欢迎控制器!

【问题讨论】:

  • 尝试把这个.htaccess 放到/nursing/.htaccess 并且把RewriteBase 改成/(而不是/nursing/)

标签: php .htaccess codeigniter


【解决方案1】:

我的 .htaccess 在这里:

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteCond $1 !^(index\.php|templates|payment\.php)
   RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
   ErrorDocument 404 /index.php
</IfModule>

【讨论】:

  • 系统真的安装了模块吗?此代码已在我的生产环境和工作环境中验证。
【解决方案2】:

mod 重写模块被 httpd.conf 禁用

【讨论】:

    【解决方案3】:

    在 .htaccess 中编写这段代码

    RewriteEngine On
    RewriteCond %{REQUEST_URI} ^/system.*
    RewriteRule ^(.*)$ index.php?/$1 [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)$ index.php?/$1 [L]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-14
      • 2014-10-28
      • 2012-06-15
      • 2013-02-27
      • 2012-09-21
      • 2011-10-12
      相关资源
      最近更新 更多