使用htaccess限制访问,但允许从网页访问


Restrict access with htaccess but allow from web pages

我如何限制对.htaccess文件Deny from all的访问,而不是所有$.post请求、$.get请求等。我如何仍然从页面访问该文件,但只需在浏览器中访问它就可以取消直接访问?

您可以通过mod_rewrite和等条件禁用使用HTACCESS的浏览器访问

RewriteCond %{HTTP_USER_AGENT} ^.*Firefox/4.*$
RewriteRule . - [R=404,L,NS]
ErrorDocument 404 /error.php?e=404

要访问页面,您可以使用cURL和等选项

curl_setopt($ch, CURLOPT_USERAGENT, "allowed_agent");