2013-04-05 189 views
2

我想在一个子目录中安装最新版本的笨的。这工作到目前为止。但现在我想从url中删除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和根目录(父文件夹)是空的。其中只有一个index.html文件。

因此,这是导致这种结构:

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

当然mod-rewrite的和已启用。

任何想法,为什么它不会工作? 我拨打404错误时调用类似http://domain.tld/dev/login

+0

什么目录是笨的index.php吗? – Pattle 2013-04-05 23:28:42

+0

的CI'index.php'文件是'dev'with应用ANS系统文件夹 – 2013-04-06 07:49:22

+0

有趣的是,它在文档根工作(改变'RewriteBase'到'/'后)。 – 2013-04-06 07:56:04

回答

1

请尝试以下代码。

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

Unfortunalty一个不eigther工作。 – 2013-04-06 07:51:06

4

你需要两件事。

config.php,配置index_page是空的,所以URL是正确创建

$config['index_page'] = ''; 

,并在您.htaccess

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

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

+0

对不起,但一个不工作。我仍然收到404错误。无论如何,是不是错过了'RewriteBase'? – 2013-04-06 07:50:15

+0

@Le_Morri我只是复制你的设置(目录结构,登录控制器等),它适用于我。并且不需要'RewriteBase'。必须有其他规则或指令,导致404错误。 – 2013-04-06 18:28:42

+0

@Le_Morri只是为了澄清,你的设置加上'index_page'空和'.htaccess',我建议。 – 2013-04-06 18:43:12