0

Currenty, I am using .htaccess file to redirect users to 404.php page when they mis-spell the url.

ErrorDocument 404 /mywebsite/404.php

In my parent directory, there are some folders like css, js in which stylesheets and js files are kept. URL for these directories is like this:

localhost/mywebsite/css
localhost/mywebsite/js

By typing above urls, all the files are listed in the browser and can be opened by clicking on them.

Is there any way to add these urls in .htaccess file and redirect the user to home page (localhost/mywebsite) when they try to type above urls on the browser?

2 Answers2

2

Options -Indexes add to .htaccess

  • I also have a folder say "ABC" which contains PHP files. Now if I type the url "localhost/mywebsite/ABC", all the PHP files are listed. So, as per you, there is no way to restrict the user to type above url? –  Apr 24 '14 at 05:57
  • Okay, it shows forbidden message to user. It is fine for me. But it would be great if I am able to redirect the user to home page instead of showing forbidden message. –  Apr 24 '14 at 06:33
  • 1
    Create /mywebsite/403.php add in 403.php ``. Add in .htaccess `ErrorDocument 403 /mywebsite/403.php` – Mitya Grebenshchikov Apr 24 '14 at 06:47
1

It sounds like you actually want to disable indexing? Have a look at how-do-i-disable-directory-browsing.

Community
  • 1
  • 1
David 'the bald ginger'
  • 1,296
  • 3
  • 20
  • 38
  • @ddtpoison777- Thanks for the link. It shows forbidden message to user. It is fine for me. But it would be great if I am able to redirect the user to home page instead of showing forbidden message –  Apr 24 '14 at 06:34
  • 1
    Have a look at http://stackoverflow.com/questions/4170098/redirect-on-deny-htaccess. PS: the .htaccess, its capabilities and how php works with it is very well documented. I suggest googling as well. :) – David 'the bald ginger' Apr 24 '14 at 06:42