How to hide the root page from public - php

I have a php website and i have pages like
xyz.com/cat/page1.html
xxyz.com/cat/page2.html
Now I want to restrict this page xyz.com/cat/ from the visitors. How do I achieve this using .htaccess?

If you hide the root directory, then no one will be able to access anything in that folder including images and other media. Yes create an .htaccess file inside the directory you wish to deny access to. Enter the following:
order allow,deny
allow from 127.0.0.1
deny from all

Related

In which wordpress folder shall I copy an xml file to prevent unauthorized access?

I want to save an xml file which it should be accessed from my first plugin only. In which wordpress folder shall I save it?
I use plesk platform and If I remove permission rights of (other) not to READ plugin cannot see the xml
If I place it inside wp-admin and logout as admin I can access the URL
Shouldnt wp-admin was not accessible?
After hours of tests the following seems to work properly.I put the file in root folder and in htaccess I add the following. I allow myself to access, block all others and I allow access to server..
<Files myfile.xml>
order deny,allow
deny from all
Allow from my_static_ip
Allow from plesk_static_ip
</Files

i want to block access to folder and its content php

i got folder called recordings on my server and i want to block access from anyone to it and its content and at the same time i want the ability to call the files inside the folder from other pages
i tried htaccess rule
Options -Indexes
its just block access to the folder but when i write specific file inside the folder the browser open it and i do not want that
and i tried another htaccess rule :
deny from all
but it make me not able to call the files on other pages and i want to be able to call them
so can anyone help me ?
Use below rule,
<Files ~ "*.php">
order deny,allow
deny from all
allow from 127.0.0.1
</Files>

Stopping direct file access using URL

I am using laravel,
In browser If I directly give the URL as below :
http://....../resources/views/users/index.blade.php
It will show the page as below :
.
I can't show page to public as above image.
How can I block access to particular folder or files ?
You need to edit/create .htaccess file of the directory you want to prevent the direct access from people.
As per the solutions given here :
Solutions - 1
I would just move the includes folder out of the web-root, but if you want to block direct access to the whole includes folder, you can put a .htaccess file in that folder that contains just:
deny from all
That way you cannot open any file from that folder, but you can
include them in php without any problems.
Solution - 2
It's possible to use a Files directive and disallow access to all
files, then use it again to set the files that are accessible:
<Files ~ "^.*">
Deny from all
</Files>
<Files ~ "^index\.php|css|js|.*\.png|.*\.jpg|.*\.gif">
Allow from all
</Files>
Also, You can Refer to Article : How to Prevent a Directory Listing of Your Website with .htaccess

Deny folder permission that is used by url (www.xxxxxx.com/data/xx.php) or browsing

How do I do to stop user/client to navigate in some of my website folders using URL like this:
www.site.com/main_folder/subfolder_Contaienr/files.php
www.site.com/main_folder/data/files.php
www.site.com/main_folder/data/also_here_text_files.txt
With this URL, the user can navigate to my folders and I do not want that he navigate to my website folders.
Also everyday I have some new folders. I use files in folder for external scope (e.g in some folder there are images and need to show users. In some folders are text files in which is JSON data or some users details.)
Is there any way to stop navigate to my folders using php Code without touching .htacess file?
It sounds like your website actually requires quite a bit of restructuring in order to achieve your goal properly but this .htaccess file can be a temporary, ahem tempermanent, band-aid in the root of your site which will deny access to all files except for whitelisted extensions:
www.example.com/.htaccess
Options -Indexes // Turn off directory listings
order allow,deny // Deny all file access
<Files ~ "\.(php|html|js|css|jpg|png|gif|ico|txt|pdf)$"> // separate file extension with a pipe |
allow from all
</Files>

How to allow downloading files with PHP, but deny direct access to directory listings

I am using Apache on my server and I'd like to allow my visitors to download resources free of charge. However, to preserve even a little bit of bandwidth I'd like to deny direct access to the root folder of the resources like this:
www.myhost.com/resources/file.wav
If the visitor removes file.wav from the URL, they have access to all sounds at once and thus I'd have people just downloading like crazy. I don't want that.
How can I stop the users from going into that root directory, and any subfolders?
The dead easiest way to do this, without even messing with .htaccess (though that is a good idea) is to simply put an index.html file in the folder and set its permissions to 700.
If you want to just turn off directory listings you can create an htaccess file with this:
<Directory /path/to/directory>
Options -Indexes
</Directory>
If you want to deny access to sub-directories, you can use this:
<Files subdirectory/*>
deny from all
</Files>
If you want to allow access to just the .wav files, you can do this:
<Files *.wav>
allow from all
</Files>

Categories