Codeigniter安装在子目录中

时间:2013-04-05 21:14:40

标签: .htaccess codeigniter mod-rewrite

我想在子目录中安装最新版本的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错误

2 个答案:

答案 0 :(得分:4)

你需要两件事。

config.php中,将index_page配置为空,以便正确创建网址

$config['index_page'] = '';

并在.htaccess

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

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

答案 1 :(得分:1)

请尝试以下代码。

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