.htaccess - 阻止直接访问所有 php 文件,除了 codeigniter 中的一些文件

标签 .htaccess codeigniter

我想在我的服务器中安装 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/

相关文章:

php - 无法将 css 文件链接到 Codeigniter

regex - 将旧域重定向到新域的主页

css - NGINX 无法加载 css

php - mysql查询以检查codeigniter中数组中是否存在字段

php - 如何获取数据库中的数据并在View中显示具体数据(Codeigniter)

php - 检查两个给定开始时间和结束时间之间是否存在时间范围

.htaccess - 301重定向.htaccess

wordpress - .htaccess 子域语言

php - 自动包含定义的 ('BASEPATH' ) 或退出 ('No direct script access allowed' );

php - 在 codeigniter 中启用 $_GET