我正在使用 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/