如何保护Php文件与htaccess,以防止外部使用或直接使用


how to Protect Php file with the htaccess to protevent external use or a direct use

例如,如果有人试图使用我的php脚本或外部使用或直接使用,我想拒绝他。
我已经在我的htaccess:

中尝试过了
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www'.)?mydomain.com(/)?.*$ [NC]
RewriteRule '.(php)$ / [NC,R,L]

但它似乎不工作,我想要的是允许php脚本只有当我调用它在我的服务器上的另一个页面。
拒绝/允许的方式也不完美,因为它有可能得到我的php脚本的内容通过CURL .

你可以尝试这样做:

RewriteCond %{REMOTE_ADDR} !^127'.0'.0'.1$
RewriteRule '.(php)$ / [NC,R,L]

或不带mod_rewrite:

Order deny,allow
Deny from all
Allow from 127.0.0.1