Reputation: 92
I have password protect my application directory but for some reason i have to give a public access to a file in a folder. i research and tried many ways but its not working. Following is my code.
# 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
My project folder structure is as follow:
root-folder
--sub-folder
--file.php
ScreenShot: https://ibb.co/R9j0QTW
Upvotes: 0
Views: 608
Reputation: 786261
Here is how it should be done:
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
Upvotes: 1