2011-10-10 54 views
3

我正在使用Codeigniter 2.0.3 | Apache 2.2.17 | PHP 5.3.4。Codeigniter .htaccess:公開訪問「公共」文件夾內的所有文件和文件夾

我想給予訪問「公共」文件夾內的所有文件和子文件夾。我已閱讀了Codeigniter wiki中的文章以及谷歌搜索結果中的所有前5個頁面,並沒有發現任何可行的方法。

這是文件樹:

- application 
    - public 
     - css 
      - style.css 
     - img 
     - js 
- system 
- .htaccess 

這是我使用從URL中移除「的index.php」,並嘗試給訪問該文件夾中的.htaccess:

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase /CodeIgniter_2.0.3 

#Removes access to the system folder by users. 
RewriteCond %{REQUEST_URI} ^system.* 
RewriteRule ^(.*)$ /index.php/$1 [L] 

#Checks to see if the user is attempting to access a valid file, 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 

#Enable access to the images and css folders, and the robots.txt file 
RewriteCond $1 !^(index\.php|public|robots\.txt) 
RewriteRule ^(.*)$ index.php/$1 [L] 
</IfModule> 

該網站工作和'index.php'不再需要的URL,但最後一個條件應該提供訪問公用文件夾,但它不適合我,所以這個http://localhost/CodeIgniter_2.0.3/public/css/style.css 文件未找到。

在config.php我有:

$config['base_url'] = 'http://localhost/CodeIgniter_2.0.3/'; 
$config['index_page'] = ''; 

請幫助。 謝謝!

+0

哪個文件夾是您的DocRoot?我假設它是'公共'? – swatkins

回答

0

以您目前的結構,則需要在最後RewriteCond更改爲:

RewriteCond $1 !^(index\.php|application\/public|robots\.txt) 

因爲你.htaccess是在同一目錄作爲您的應用程序文件夾和公共文件夾在你的應用程序文件夾,您需要明確地標記應用程序/公用文件夾爲可訪問。

+0

但是,我會說,你的結構不是常態。通常,你的'public'文件夾與你的應用程序和系統文件夾相鄰,而不是其中的任何一個。 – swatkins

+0

謝謝,剛剛在樹上移動'公共',它的工作很棒! – Jonathan

相關問題