2013-04-05 110 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