gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 01:58:40 24 4
gpt4 key购买 nike

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com