我想在我的服务器中安装 Codeigniter
旁边的另一个脚本。问题是 Codeigniter 默认包含一个 .htaccess
文件,该文件具有以下代码以防止直接访问 php 文件:
# Hide all PHP files so none can be accessed by HTTP
RewriteRule (.*)\.php$ index.php/$1
如何向这段代码添加一些异常(exception)?!
如果我的 PHP 文件位于 .htaccess
所在的文件夹之外的另一个文件夹中,我应该如何异常(exception)?!
我的整个代码如下:
# set it to +Indexes
Options -Indexes
Options SymLinksIfOwnerMatch
# Set the default file for indexes
DirectoryIndex index.php
<IfModule mod_rewrite.c>
# mod_rewrite rules
RewriteEngine on
# If the file is NOT the index.php file
RewriteCond %{REQUEST_FILENAME} !index.php
# Hide all PHP files so none can be accessed by HTTP
RewriteRule (.*)\.php$ index.php/$1
# If the file/dir is NOT real go to index
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
</IfModule>
# If Mod_ewrite is NOT installed go to index.php
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
最佳答案
像这样添加另一个排除条件:
# If the request is not from /some-folder/
RewriteCond %{REQUEST_URI} !^/some-folder/ [NC]
# If the file is NOT the index.php file
RewriteCond %{REQUEST_FILENAME} !index.php
# Hide all PHP files so none can be accessed by HTTP
RewriteRule ^(.*)\.php$ index.php/$1 [L,NC]
关于.htaccess - 阻止直接访问所有 php 文件,除了 codeigniter 中的一些文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18513273/