Eshwar Hebbur
Eshwar Hebbur

Reputation: 3

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?

Upvotes: 0

Views: 383

Answers (1)

Mohit Kumar
Mohit Kumar

Reputation: 940

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.

Upvotes: 0

Related Questions