Allowing only certain files to view by .htaccess

前端 未结 2 1680
北恋
北恋 2021-02-07 17:50

i have almost 20 pages on server, but i want only a file named abc.php, which users can watch. i want if user forcefully open the other files like //example.com/some.php .htacce

相关标签:
2条回答
  • 2021-02-07 18:06

    Its safest to move the files you don't want the users to access to a directory which is not in the root directory of the web server.

    Like if the root directory of my site is this:

    /var/www/html/my_web_site/public/index.php
    

    I can put the non-public files in another directory like this:

    /var/www/html/my_web_site/config.php
    /var/www/html/my_web_site/auth.php
    /var/www/html/my_web_site/db.php
    

    And include the files like this in index.php:

    include("../config.php");
    include("../auth.php");
    include("../db.php");
    

    Whit this, you don't have to risk to accidentally delete or forget to copy the .htaccess file.

    0 讨论(0)
  • 2021-02-07 18:27

    This .htaccess-file will only allow users to open index.php. Attempts to access any other files will result in a 403-error.

    Order deny,allow
    Deny from all
    
    <Files "index.php">
        Allow from all
    </Files>
    

    If you also want to use authentication for some of the files, you may simply add the content from your current file at the end of my example.

    0 讨论(0)
提交回复
热议问题