10

I am uploading my project containing folders with all the scripts, PHP, CSS etc, and the index.html

Let's say the URL looks like this www.mydomain.com/project/web/index.html

Inside the parent folder "project", all my files are visible and easily accessible to download (which they shouldn't) if they simply enter www.mydomain.com/project/

Question: Is there any way to HIDE all the parent folders and documents and only make my /index.html accessible?

My server is not an Apache so I can not setup an .htaccess file and build rules to hide/redirect and return a 404 Error page.

Mykita
  • 437
  • 2
  • 8
  • 31
  • 2
    Possible duplicate of [What is the best way to hide a websites folder/ directory files](https://stackoverflow.com/questions/19439348/what-is-the-best-way-to-hide-a-websites-folder-directory-files) – Don't Panic Sep 11 '17 at 11:46
  • My server is not an Apache so I can not set up an .htaccess file and build rules to hide/redirect and return a 404 Error page. – Mykita Sep 14 '17 at 17:49
  • 2
    What web server *are* you running? – j08691 Sep 14 '17 at 17:53
  • 2
    @Mykita, try to extend your question by providing us more information. – voloshin Sep 14 '17 at 17:54
  • How do I know what server I am running? I just know that it is not Apache. I am simply hosting my page from a domain provier (https://www.domeneshop.no/) – Mykita Sep 14 '17 at 17:59
  • At least the domeneshop.no site itself is using apache. – allo Sep 21 '17 at 08:44

5 Answers5

7

You could set up a index.html in your projects folder or any other folder that you don't want them to have access.

Then in those index.html pages you can add redirects to push the user to your true homepage. You would place this code in the head of that index.html

<meta http-equiv="refresh" content="1; url=www.mydomain.com/project/web/">
        <script type="text/javascript">
            window.location.href = "www.mydomain.com/project/web/"
        </script>

I still think the best way is to use a .htaccess. But if you have no other choice this will work for folder based access.

This would not prevent people from accessing the file directly such as www.mydomain.com/project/file.txt

Niles Tanner
  • 3,911
  • 2
  • 17
  • 29
  • What is the role of meta tag here ? how does it work with the url ? – bhansa Sep 21 '17 at 11:49
  • 1
    @bhansa This HTML snippet is really two different redirects. Why two? just to double up. For example the user might block JavaScript, so as a fall back the meta tag will handle the redirection. If you want to know more about that meta tag I would look at this resource: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta – Niles Tanner Sep 21 '17 at 12:08
  • Thanks for clearing that up for me ,didn't know we can use urls in meta. – bhansa Sep 21 '17 at 12:15
2

Actually, your server is Apache.

This is from their documentation:

What is the difference between the old and new webservers? The operating system on all new webservers are running Debian 8 Jessie, up from Debian 7 Wheezy.

Apache is upgraded from Apache 2.2 to Apache 2.4. If you are running your own .htaccess-file (especially accesscontrol) on your webhotel, this may need to be upgraded. Check Apache-documentation for more information.

We are now using uWSGI to run PHP, instead of suPHP (mod_suphp).

Link to documentation: FAQ

Link to rewrite_mod for Apache 2.4 Apache 2.4

SouXin
  • 1,565
  • 11
  • 17
1

You can try my idea.

  1. Create an index.html or index.php file inside of a folder you dont want the user to access, for example, the project folder; so when a user attempts to visit www.mydomain.com/project and see the content, the index.html will be showed instead. OR
  2. Create a condition there which redirect the user to index.html using php or JavaScript.
Blues Clues
  • 1,694
  • 3
  • 31
  • 72
0

There are couple of ways to tackle this

You can try using a folder structure like Laravel does, setting up a MVC (Model-View-Controller) architecture can restrict to viewing only specific requests.

Following the REST pattern. If someone goes to

mydomain.com/project //Returns 404 error

The controller for /project must be defined, if it's not defined, it will throw a 404 error

Similarly, if only you define a project view like

Route::get('project', 'This is the project page');

That's the only way someone can access a /project directory, I would suggest you learn about REST patterns and follow a MVC/MTV responsibility driven design.

Dhiraj
  • 2,687
  • 2
  • 10
  • 34
0

Your server appears to be running PHP, at least according to your question. This means that you have most likely done something wrong there. But as Voloshin commented, you need to extend your question. Honestly, scan your PHP to check to see if you have a link that just says "./" instead of "index.html". If you don't have something like that in there, then check all of your <a href="link" /> link </a> tags to make sure that you haven't screwed up there. All the best with your code!

Finnegan
  • 33
  • 5