In order to limit access to the directory for all IP except one, you need to put in it .htaccess with the following content:

Order Deny,Allow Deny from all Allow from 1.1.1.1 

You can do this in virtual hosts in this way.

 <Directory "/var/www/html/mysite/my_folder"> Order Deny,Allow Deny from all Allow from 1.1.1.1 </Directory> 

But how to solve this problem if there is no my_folder directory and this is a virtual path?

The following is the contents of the .htaccess directory mysite

/var/www/html/mysite/.htaccess:

 AddDefaultCharset utf-8 Options +FollowSymLinks IndexIgnore */* RewriteEngine on RewriteRule ^favicon.ico$ - [F,L] # если директория или файл существуют, использовать их напрямую RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # иначе отправлять запрос на файл index.php #RewriteRule . index.php <-- было RewriteRule ^([^/].*)$ /index.php/$1 [L] # <-- стало 

    2 answers 2

    the contents of the .htaccess file can only affect the behavior of an appropriately configured http server (and not all implementations of such a server can do this out of the box), to which http clients are connected via the http protocol.

    you are using the scp program ( ssh client) connected to the openssh server via ssh protocol.

    so there is nothing surprising (either strange or wrong) that you managed to copy the file, no: it should have happened - neither the presence, nor the absence, nor the contents of the .htaccess file located anywhere within the Earth’s orbit, could in no way affect this situation.

    • Uh ... I don't see any mention of scp and file copying in the question. And the more I can’t understand what the “virtual path” means in relation to the ssh protocol ... - Pavel Mayorov
    • All the more surprising to see the green check mark to the left of the answer. What is going on? - Pavel Mayorov
    • @PavelMayorov, the author made an amendment to the question, because of which the essence has changed somewhat. - aleksandr barakin
    • Hmm, that is, the author first noted the answer as a solution, and then brought the question to the mind at which the answer became stupid? .. Well, ok :) - Pavel Mayorov
    • @PavelMayorov, if you see fit, roll back the last edit of the issue. I get a person interested, because I do not have the moral right to do so. - aleksandr barakin

    In order to set the rules for virtual paths in the Apache settings, you need to use <Location> instead of <Directory> . So the answer to the current version of the question will be:

     <Location /my_folder/> Order Deny,Allow Deny from all Allow from 1.1.1.1 </Location>