我想限制对我的网站的直接IP访问。我发现了涉及.htaccess的几种解决方案,但是没有用。我还通过apache虚拟主机配置找到了一种解决方案,该解决方案在我通过CPanel安装SSL证书之前一直工作良好。我完全不知道httpd.conf文件中所做的更改,但是即使卸载SSL证书,重定向设置也无法使用。
这是我当前的虚拟主机设置:
NameVirtualHost 192.168.1.1:80 NameVirtualHost *
<VirtualHost 192.168.1.1:80>
ServerName mysite.com
ServerAlias www.mysite.com
DocumentRoot /home/rotate/public_html
ServerAdmin me@mysite.com
UseCanonicalName Off
## User rotate # Needed for Cpanel::ApacheConf
UserDir disabled
UserDir enabled rotate
ScriptAlias /cgi-bin/ /home/rotate/public_html/cgi-bin/
</VirtualHost>
<VirtualHost 192.168.1.1:80>
ServerName 192.168.1.1
Redirect 403 /
ErrorDocument 403 "Sorry, direct IP access not allowed."
DocumentRoot /usr/local/apache/htdocs
ServerAdmin me@mysite.com
UseCanonicalName Off
UserDir disabled
</VirtualHost>
<VirtualHost *>
ServerName server.mysite.com
DocumentRoot /usr/local/apache/htdocs
ServerAdmin me@mysite.com
UserDir disabled
</VirtualHost>
NameVirtualHost 192.168.1.1:443
<VirtualHost 192.168.1.1:443>
ServerName mysite.com
ServerAlias www.mysite.com
DocumentRoot /home/rotate/public_html
ServerAdmin me@mysite.com
UseCanonicalName Off
UserDir disabled
UserDir enabled rotate
ScriptAlias /cgi-bin/ /home/rotate/public_html/cgi-bin/
SSLEngine on
#SSL stuff here
</VirtualHost>
IP和名称被通用名称代替。自安装SSL证书以来,“重定向403 /”部分不起作用。如果有人能阐明我在这里做错了什么,我将不胜感激。谢谢。