Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

block root and subfolder using single .htaccess with deny/allow

Posted on 2011-09-06
4
Medium Priority
?
1,375 Views
Last Modified: 2013-12-13
Is it possible to restrict access to the root folder and a sub folder using one .htaccess? Using deny/allow?

I have one .htaccess file in the root which has:

order deny,allow
deny from all
allow from 127.0.0.1
allow from 127.0.0.2

This blocks access to the root for all IP addresses other than 127.0.0.1 and 127.0.0.2

However I would also like to block a subfolder but I can't add another .htaccess file to any sub folders but I get internal server error if I have this:

order deny,allow
deny from all
allow from 127.0.0.1
allow from 127.0.0.2

<Directory "/xxxx/xxxx/xxxx/xxxx/domain.tld/images">
Options All
AllowOverride All
Order allow,deny
deny from all
</Directory>

Please advise
0
Comment
Question by:ellandrd
4 Comments
 
LVL 9

Expert Comment

by:parparov
ID: 36492453
What does Apache log say when you try to access that URL?
0
 
LVL 51

Accepted Solution

by:
Steve Bink earned 2000 total points
ID: 36517728
You get an error because the <Directory> container can only be used in the server config or <VirtualHost> container.  If you need a per-directory setting in an .htaccess file using Allow/Deny, you need to put that file in the target directory.

Another option is to use mod_rewrite.  The parent's .htaccess file will still be processed in the chain.  Something like this:

RewriteRule ^/?images(/.*)? - [F]

Open in new window

0
 
LVL 80

Expert Comment

by:arnold
ID: 36517820
You need to alter the order of your to allow, deny.
http://www.maxi-pedia.com/Order+allow+deny

If you are blocking/restricting access at the root, what additional restrictions are you placing down the road?

Where are you adding the extended directory?

use apachectl configtest to test the configuration file httpd.conf.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Originally, this post was published on Monitis Blog, you can check it here . It goes without saying that technology has transformed society and the very nature of how we live, work, and communicate in ways that would’ve been incomprehensible 5 ye…
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
Suggested Courses

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question