Question

I have a website that has an include folder which contains php templates and functions. If a user tries to access that folder. It may not harm website but I don't want my users to see those templates in an UN-organized manner. Instead, I want to restrict the user if he tries to directly access those files within include folder and redirect him to homepage.

Was it helpful?

Solution

Put this in an .htaccess file in that directory:

Deny from all

This is assuming you're using Apache or another web server that knows how to read and process .htaccess files.

For the redirect, instead of Deny from all you could try this instead:

RedirectMatch 301 ^/includes/$ http://www.yoursite.com/

OTHER TIPS

You can configure the server such that this folder is not available to the public. Alternately, structure the site so this folder is below the siteroot - this makes it completely invisible to the public. Simply adjust your include paths and you're done. I prefer this solution, because the files are completely off the radar unless you are logged in and have access to the file system.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top