skip to Main Content

How can I deny direct access to a URL through .htaccess file?

The URL for example is

www.example.com/course/reset-password

The file is located within a course folder and the alternative and all files in that folder can allow direct access with exception of reset-password.php.

2

Answers


  1. Inside corse/.htacccess you can have just this rule to block access:

    RewriteEngine On
    
    RewriteCond %{THE_REQUEST} /reset-password [NC]
    RewriteRule ^ - [F]
    
    Login or Signup to reply.
  2. If you wish to deny access to a specific file (as opposed to a URL) then consider using mod_authz_core (Apache 2.4) instead of mod_rewrite. For example:

    <Files "reset-password.php">
    Require all denied
    </Files>
    

    This has less chance of being overridden than mod_rewrite.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search