Which method is more secure/suitable for blocking

2019-09-06 21:38发布

I'm trying to use .htaccess to block external access to my website's /includes/ directory which only includes processing PHP files. Both methods below 'work' but I prefer the latter because it doesn't leave the user with a error page. Can anybody let me know if it is less secure?

Is it better to use this:

<Directory "/includes">
  Deny from all
</Directory>

Or this:

RedirectMatch 301 ^/includes/.*$ http://www.mymainurl.com

Or is something else more appropriate?

The website content is dynamically served by an index.php, so files within the /includes/ folder need to remain accessible via PHP's include function.

1条回答
forever°为你锁心
2楼-- · 2019-09-06 22:01

Alternatively, you can return a 404 to make people think the includes directory doesn't even exist:

RewriteEngine On
RewriteRule ^includes/ - [L,R=404] 
查看更多
登录 后发表回答