apache - 代码点火器.htaccess : Give public access to all files and folders inside the 'public' folder

标签 apache .htaccess codeigniter

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

我想授予对“公共(public)”文件夹中所有文件和子文件夹的访问权限。我已经阅读了 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>

该网站正在运行,URL 中不再需要“index.php”,但最后一个条件应该允许访问公共(public)文件夹,但它对我不起作用,所以这个 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 与您的应用程序文件夹位于同一目录中,而您的公共(public)文件夹位于您的应用程序文件夹中,因此您需要明确地将应用程序/公共(public)文件夹标记为可访问。

关于apache - 代码点火器.htaccess : Give public access to all files and folders inside the 'public' folder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7718941/

相关文章:

apache - display_errors 设置为 On 但在 phpinfo() 中显示 Off

.htaccess - 规范 URL 不重定向

.htaccess - Cloudflare DNS - 如何将所有子域重定向到根域?

codeigniter - 在 codeigniter 中未获取 cookie 值

python - apache上的python flask应用程序的随机问题

python - 选择 wsgi 或 cgi 或 fastcgi 来处理单个 python 脚本

php - 从不同的文件和目录自动加载类和函数

database - Codeigniter 从模型中获取一对多关系并在 View 中进行解析

php - 在 Codeigniter 中从一个 View 中的两个表获取数据(取决于查询)

php - Apache 处理 PHP 数组标记作为结束标记