skip to Main Content

I know this is a common question, but I just can’t figure out how to do it.

After many unsuccessful attempts, dozens of tutorials and SO posts I gave up and decided to ask a new question here.

So, this is what I have:

  • a vary basic file host without the ability to alter any Apache settings
  • a subdomain provider
  • following file and directory structure:
-root
|-subfolder1
|-subfolder2
 |-subfolder1
  |-index.html
  |-somescript.php

Now I just want to protect the folder "subfolder2" and all of its contents.

I managed to protect a subfolder of a subfolder of the root directory, but not a subfolder within the root directory itself.

I am totally lost.

Please, can anybody help me out?

2

Answers


  1. Chosen as BEST ANSWER

    WOW!

    Your code was not needed. All I had to do was clearing the cache and cookies and then the login prompt popped up. That simple. Thanks for your effort though!

    BTW. this is what I have done so far:

    file and directory structure as follows:

    -root
    ...
    |-subfolder2
     |-subfolder1
     |-.htaccess
     |-.htpasswd
     |-index.html
     |-script.php
    

    .htaccess file:

    AuthType Basic
    AuthName "Protected Area"
    AuthUserFile /users/XYZ/root/subfolder2/.htpasswd
    Require valid-user
    

    .htpasswd file:

    MrX:$blah1blah2blah3.some.encoded.password
    
    

    Cleared browser cache and cookies. Now when I go to http://XYZ.domain.com/subfolder2 the "login" prompt pops up and that's all I needed. There's no secret or vulnerable data in this folder, I just don't want bots and crawlers to browse it.

    Many thanks anyway stay safe and have a nice pre new years eve time


  2. If I understood your question you want to forbid the access to any URL which has subfolder2 in it, if this is the case then please try placing these rules into your .htaccess file. Please make sure you clear your browser cache before testing your URLs.

    RewriteEngine ON
    RewriteCond %{REQUEST_URI} subfolder2 [NC]
    RewriteRule ^ - [F]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search