编写.htaccess规则,禁止一切非法域名访问我们网站

查看Apache访问日志,遇到不少非法域名解析过来,可能影响我们网站SEO,对网站搜索排名非常不利,感觉非常不爽。遇到这个问题怎么办呢?我们可以编写.htaccess规则,禁止一切非法域名访问本站,即只有www.xieyincai.com和xieyincai.com可以访问。

编写.htaccess规则

RewriteEngine On
RewriteBase /

#xieyincai.com自动跳转到www.xieyincai.com
RewriteCond %{HTTP_HOST} ^xieyincai.com$ [NC]
RewriteRule ^(.*)$ http://www.xieyincai.com/$1 [L,R=301]

#禁止非法域名访问
rewritecond %{http_host} !^xieyincai.com$ [NC]
rewritecond %{http_host} !^www.xieyincai.com$ [NC]
#-禁止规则
rewriterule ^.* - [F,L]

现在用非法域名访问本,会出现下面页面:

Forbidden

You don't have permission to access /index.php on this server.

OK,至此,我们大功告成了。。

Leave a Reply

Your email address will not be published. Required fields are marked *