Search code examples
phpapache.htaccesshttp-redirectrestrict

how to restrict and redirect from certain pages in php


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.


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/