我正在使用Codeigniter 2.0.3 | Apache 2.2.17 | PHP 5.3.4。

我想访问“ public”文件夹中的所有文件和子文件夹。我已经阅读了Codeigniter Wiki中的文章,以及Google搜索结果的前5页,但没有发现任何有效的方法。

这是文件树:

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


这是我用来从网址中删除“ 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>


该网站正在运行,URL中不再需要'index.php',但最后一个条件应该是可以访问公用文件夹,但对我而言不起作用,因此此http://localhost/CodeIgniter_2.0.3/public/css/style.css
找不到文件。

在config.php中,我有:

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


请帮忙。
谢谢!!!

最佳答案

使用当前结构,您需要将最后一个RewriteCond更改为:

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


因为.htaccess与应用程序文件夹位于同一目录中,而公用文件夹位于应用程序文件夹中,所以您需要将应用程序/公用文件夹显式标记为可访问。

关于apache - Codeigniter .htaccess:公开访问“public”文件夹中的所有文件和文件夹,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7718941/

10-12 00:13
查看更多