I just took over management of a small HTML website. I discovered the security on the website was almost non-existent because full directory browsing was possible.
I have since disabled directory browsing through
.htaccess and now if someone tries to access a folder directly it gives an unauthorized access. The error it reports is:
Not Authorized to View This Page [CFN #0004]
This is great but it doesn't help people who might not know what to do next. I would like this error to redirect to the homepage. What is the best way to do this through
.htaccess? I'm not sure if it should be done based on the error or whether it should be done with something like an if/then as in "if no
index.html then redirect to
I also want to be sure this only happens at the browser level and doesn't affect the crawlers. For example I have a downloads directory
/downloads so if someone goes to
http://example.com/downloads/ (and I guess
http://example.com/downloads) then the browser redirects to the homepage but I don't want the search crawlers to be denied access to the downloads directory so they can index the pdfs. So the search crawlers should be able to access
http://example.com/downloads/file.pdf. There are about five directories I want to redirect to the homepage. They're the standard
/images, etc. Besides the root that contains the HTML files for the site the only other directory that has actual content is the downloads directory. For simplicity sake I guess it would be good to have something that does this for all directories instead of specifying each directory.
I also have three more questions beyond how to achieve this redirection:
What type of error is "Not Authorized to View This Page [CFN #0004]"? (Meaning what type of webserver gives this... Apache?... IIS?... I haven't seen it before and is it a 401 error?) I tried googling this but couldn't find any info on it other than people posting that they have the error and what to do about it.
Does disabling directory browsing affect the search crawlers? I haven't seen any errors on Google Search Console but want to be sure. I'm assuming this just stops directory browsing through the web browser?
I haven't done a lot of stuff with
.htaccessand I know it's quite powerful. Is there more I can do with
.htaccessto secure the directories/files from being hacked besides disabling directory browsing?
I tried googling for a solution but couldn't find anything. I found a lot of directory redirection questions but they seemed more for 301s. A similar solution might work for me but the problem is I don't know what kind of error is being produced by the server. If there is a solution already posted please direct me to that page.
If you need more info don't hesitate to ask.