Search code examples
phplinux.htaccesselgg

how to use htacces to restrict access to all files in a folder and it's subfolders and redirect to main?


So I'm on a 15-day trial of my (already paid) webhosting and they seem very good, at least they did until I got my FTP.

I have a php script that needs a folder outside of the root directory


Example:

website root:

/users/websites/public_html/ <- folder which users / browsers have access to

The script needs a folder here:

/users/websites/ <- above the root

for example /users/websites/sensetive_data/ <- browsers cannot acces this


but that's impossible on my web-host "because it's a shared hosting" <- their answer. And they can't change the root path.

So I cannot create any directories or files above /users/websites/public_html/

So, well, to no cancel my trial immediately, maybe I will try to do it in another way, I want to use htacces to restrict acces to a directory, and all the files in it and it's subdirectories,

So I can move the 'sensetive_data' folder to /users/websites/public_html/sensetive_data

I want it to redirect to the main page (so when accessing /users/websites/public_html/sensetive_data/* [http://example.com/sensetive_data/*] it will go to /users/websites/public_html/ [http://example.com/],

so even if the user knows the exact url, he/she will be redirected. How can I accomplish that?


Solution

  • If you want to do a redirect for a folder, say /users/websites/sensitive_data/

    create a file in that folder called .htaccess and add the following (and specify the url to redirect to)

    Options -Indexes
    ErrorDocument 403 http://mysite.net/