如何使用htaccess从搜索引擎隐藏文件夹

时间:2013-07-07 13:28:09

标签: apache security .htaccess mod-rewrite

有没有办法使用htaccess隐藏搜索引擎中的管理员文件夹?我知道可以使用robots.txt完成,但robots.txt本身很容易访问。

由于

2 个答案:

答案 0 :(得分:0)

一个简单的解决方案是使用.htaccess密码保护整个管理文件夹。

在您要锁定的文件夹中的.htaccess文件中输入以下内容。

AuthUserFile /absolute_path/to/.htpasswd
AuthType Basic
AuthName "Administration Area"
Require valid-user

然后使用htpasswd生成用户名和密码,生成的文件应存储在/absolute_path/to/.htpasswd指定的位置

您还应该能够将.htaccess文件添加到admin文件夹中,并检查用户代理并以这种方式阻止访问:

RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} ^Googlebot [OR]
RewriteCond %{HTTP_USER_AGENT} ^Crawler
# fill up with other user agents you would like to block here
# and redirect to some other page
RewriteRule ^(.*)$ http://example.com/404.html

答案 1 :(得分:0)

提出所有用户代理的lis真是令人生畏,请记住搜索代理值也可以伪造。

说过以下内容适用于大多数搜索引擎:

通过httpd.conf启用mod_rewrite和.htaccess,然后将此代码放在.htaccess目录下的DOCUMENT_ROOT中:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_USER_AGENT} (googlebot|adsbot-google|bingbot|msnbot|psbot|gigabot|twitterbot|linkedinbot|yahoo-mmcrawler|pingdom\.com_bot) [NC]
RewriteRule ^folder-to-hide/ - [L,F,NC]
相关问题