【问题标题】:Codeigniter installation in subdirectory [closed]在子目录中安装 Codeigniter [关闭]
【发布时间】:2013-03-28 10:40:37
【问题描述】:

我想在子目录中安装最新版本的 codeigniter。到目前为止有效。但现在我想从网址中删除index.php。所以我在子文件夹中有这个.htaccess 文件。

RewriteEngine On
RewriteBase /dev/

# Removes trailing slashes (prevents SEO duplicate content issues)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]

###

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

子文件夹的名称是dev,webroot(父文件夹)是空的。里面只有一个index.html 文件。

所以这导致了这个结构:

/var/www/
    index.html
    dev/
        ci installation here
        .htaccess

当然mod-rewrite 已启用。

任何想法为什么它不起作用? 调用 http://domain.tld/dev/login 之类的内容时出现 404 错误

【问题讨论】:

  • codeigniter index.php在什么目录?
  • CI index.php 文件在 dev 和应用程序 ans 系统文件夹中
  • 有趣的是它在文档根目录中工作(在将RewriteBase更改为/之后)。
  • 好的...我忘记激活 AllowOverride ...

标签: .htaccess codeigniter mod-rewrite


【解决方案1】:

你需要两件事。

config.php中,配置index_page为空,这样就可以正常创建url了

$config['index_page'] = '';

在你的.htaccess

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php/$0

Codeigniter 提供的这些子目录中的.htaccess 文件已经禁止访问systemapplication 目录。

【讨论】:

  • 很抱歉,那个不工作。我仍然收到 404 错误。是不是缺少RewriteBase
  • @Le_Morri 我刚刚复制了您的设置(目录结构、登录控制器等),它对我有用。而且不需要RewriteBase。一定有其他规则或指令导致 404 错误。
  • @Le_Morri 澄清一下,我建议您的设置加上 index_page 为空和 .htaccess
  • 问题实际上不在.htaccess 也不在config.php。服务器管理员忘记将AllowOverride 设置为all。它被设置为none
【解决方案2】:

试试下面的代码。

RewriteEngine on
RewriteCond $1 !^(index\.php|public|\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1

【讨论】:

  • 很遗憾一个人也不能正常工作。
猜你喜欢
  • 2014-02-23
  • 2011-01-31
  • 2013-02-12
  • 1970-01-01
  • 2018-06-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多