简体   繁体   中英

How to prevent users from accessing files directly from url?

I have a php file called home.php that uses main.php in its code. Both are in the same directory. I don't want people from accessing main.php by typing it in the url like: http://localhost/main.php

The code in .htaccess is:

<Files main.php>
order deny,allow
deny from all
</Files>

But this is preventing home.php also from accessing main.php .

Can anyone help me with this?

Try This One

You can add lines to .htaccess file

Deny from all
ErrorDocument 403 "nothing is here"

It will display the "nothing is here" message in case of the unauthorised access.

If you want to redirect by an error code to a certain page then you can define a command as follows:

ErrorDocument 404 "/errors/404.html"

It will redirect to the /errors/404.html and show the custom page not found screen.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM