Software, your way.
How To Get Good Custom Software
(Download)
(PDF)
burger menu icon
WillMaster

WillMaster > LibrarySecurity and Blocking

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

Access to One File in Locked Directory

It's possible to lock a directory so no browser or internet robot can access any files in it.

It's a wonderful place for logs and other files with content that's nobody's business but yours. Just because it's locked to internet access, however, doesn't mean it's locked to software running on your server.

Here is the one line to put into the .htaccess file located in the directory to be locked.

Deny from all

The above is explained in the Effective Block for Browsers and Bots Willmaster Library article.

This article describes how to permit access to a specific page within that otherwise-locked directory.

It might be access to a log file you're temporarily granting access to. Or a sales page. Perhaps a page describing why they can't access anything else in the directory.

Whatever your reason might be, access can be granted to a specific page with the following lines in the locked directory's .htaccess file.

SetEnvIf REQUEST_URI /page.php$ let_me_in=1
Order Deny,Allow
Deny from all
Allow from env=let_me_in

Replace page.php with the file name of the page to grant public access to.

The let_me_in label may be changed if you prefer a different label. Just make certain all instances of let_me_in are changed the same way.

When the lines are published in the .htaccess file located in the otherwise-locked directory, browser and robot access to the specified file is permitted without granting access to anything else.

There is a way to grant access to more than one specific file.

To do that, repeat the first line of the .htaccess code provided above for each file to grant access to. That would be repeating the SetEnvIf… line. Here is the .htaccess code that grants access to three files.

SetEnvIf REQUEST_URI /a-page.php$ let_me_in=1
SetEnvIf REQUEST_URI /another-page.php$ let_me_in=1
SetEnvIf REQUEST_URI /a-third-page.php$ let_me_in=1
Order Deny,Allow
Deny from all
Allow from env=let_me_in

The above grants internet access to a-page.php, another-page.php, and a-third-page.php.

Add and remove the SetEnvIf… lines as appropriate for your intent.

Locked directories do come in so very handy for confidential files that nevertheless need to be on the server, such as log files that continually get updated. It is also a good temporary location for backup files server software makes for you.

Unless specific access is granted, no locked-directory file can be accessed by internet robot or browser. You now know how to grant that specific access as necessary.

(This article first appeared in Possibilities newsletter.)

Will Bontrager

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2024 Will Bontrager Software LLC