1

Sorry for the my noob questions, i'm sure their's an answer out there but i'm not sure what to search. I was hoping to find out what the best way to redirect someone to my homepage when they access a directory in the browser instead of a file.

for example:

When i access http://example.com/testdir it will give me a ftp like screen instead i want to redirect them to http://example.com unless they access an actual file i.e. http://example.com/testdir/test.html to which i want to show the html.

Also is their any security danger leaving it like this?

Thanks!

AC Buzz
  • 53
  • 3
  • I'd just turn `indexes` off so they get an error message. Redirecting to the homepage would be unexpected behaviour (You asked for `/example`? Well you can find that at `/`! Huh?) – Quentin Mar 04 '19 at 10:28
  • How would i turn off "indexs"? – AC Buzz Mar 05 '19 at 03:00
  • https://duckduckgo.com/?q=apache+indexes leads to http://www.ducea.com/2006/06/26/apache-tips-tricks-disable-directory-indexes/ – Quentin Mar 05 '19 at 07:53

1 Answers1

0

You can put on every submenus file name index.html that have this markup:

<html>
  <head> 
    <meta http-equiv="refresh" content="0; URL=http://www.YOURWEBSITE.com/" /> 
  </head>
  <body>
    <h1>Page not found</h1>
  </body>
</html>

Another way is to set either in the server config file or in the .htaccess of each directory. You can find here the way https://developer.mozilla.org/en-US/docs/Web/HTTP/Redirections

Edit: check this approach: https://stackoverflow.com/a/14063270/6525081

A. Meshu
  • 4,053
  • 2
  • 20
  • 34
  • hey i'm not sure how this would help? if i access the directory and not the file wouldn't i still have the same problem? – AC Buzz Mar 05 '19 at 03:10
  • The server is searching automatically index.html file. When it absent iit either shows directory ttree or 404 etc. Have you tried it before downvote??? – A. Meshu Mar 05 '19 at 09:22