apache - 从 apache .htaccess 密码保护站点中排除目录中的文件
问题描述
我有密码保护我的应用程序目录,但出于某种原因,我必须公开访问文件夹中的文件。我研究并尝试了很多方法,但它不起作用。以下是我的代码。
# Welcome to your htaccess file.
# Remember that modifying this file can break the entire website
# so please edit carefully.
RewriteEngine On
RewriteBase /cms
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /cms/index.php/$1 [L]
<IfModule mod_env.c>
SetEnv CI_ENV production
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
AuthType Basic
AuthName "Restricted Area"
AuthUserFile /home/root/.htpasswd
require valid-user
# allow public access to the following resources
#SetEnvIf Request_URI "(folder/)$" allow
#SetEnvIf Request_URI "(path/folder\file.php)$" allow-Uri
# Deny by default
# Order deny,allow
# Deny from all
Order allow,deny
#Allow from env=allow-Uri
<Files "path\to\file.php">
Allow from all
</Files>
Satisfy ANY
我的项目文件夹结构如下:
root-folder
--sub-folder
--file.php
解决方案
这是应该如何完成的:
SetEnvIfNoCase Request_URI "^/path/to/file\.php" ALLOW_URI
AuthType Basic
AuthName "Restricted Area"
AuthUserFile /home/root/.htpasswd
Require valid-user
Satisfy any
Order deny,allow
Deny from all
Allow from env=ALLOW_URI
推荐阅读
- npm - 如何发布没有标签的 npm 包?
- html - Nodejs:从html中获取数据
- angular - 未定义列表对象的属性切片
- java - 将 Android 应用上的所有链接设置为在应用内(如 Twitter)而不是浏览器中打开
- javascript - Discord.js 在嵌入链接中将 api 连接到不和谐机器人
- azerothcore - 255 有趣的服务器闪避问题
- drupal - Drupal 自定义模块路由问题
- tableau-api - 如何仅计算 tabluea 中的特定值?
- android - 如何将通过应用程序注册的“用户池”(Cognito 服务)中的用户与手动创建的事物(物联网核心服务)相关联?
- yii2 - 我在 yii2 中使用 dropzone 但我有错误