背景:apache虚拟主机有两个域名 aaa.com bbb.com 其中bbb.com 访问的时候跳转到aaa.com,并且给该虚拟主机做了访问控制,只允许127.0.0.1访问。
问题:当访问bbb.com时,它是先跳转到aaa.com,还是直接403呢?
配置:测试:
# curl -x172.7.15.101:80 aaa.com -I
HTTP/1.1 403 Forbidden
Date: Tue, 29 Sep 2015 10:49:21 GMT
Server: Apache/2.2.16 (Unix) PHP/5.3.10
Content-Type: text/html; charset=iso-8859-1
# curl -x172.7.15.101:80 bbb.com -I
HTTP/1.1 301 Moved Permanently
Date: Tue, 29 Sep 2015 10:49:26 GMT
Server: Apache/2.2.16 (Unix) PHP/5.3.10
Location: http://aaa.com/
Content-Type: text/html; charset=iso-8859-1
此时可能会怀疑,访问控制的位置是在下面,所以调换位置:再次测试:
DocumentRoot "/usr/local/apache2/docs/aaa.com"
ServerName aaa.com
ServerAlias bbb.com
Order deny,allow
Deny from all
Allow from 127.0.0.1
RewriteEngine on
RewriteCond %{HTTP_HOST} ^bbb.com$
RewriteRule ^/(.*)$ http://aaa.com/$1 [R=301,L]
一样的效果。 所以得出结论。
结论: 301跳转优先级会高于访问控制!
问题:当访问bbb.com时,它是先跳转到aaa.com,还是直接403呢?
配置:
- DocumentRoot "/usr/local/apache2/docs/aaa.com"
- ServerName aaa.com
- ServerAlias bbb.com
- RewriteEngine on
- RewriteCond %{HTTP_HOST} ^bbb.com$
- RewriteRule ^/(.*)$ http://aaa.com/$1 [R=301,L]
- Order deny,allow
- Deny from all
- Allow from 127.0.0.1
# curl -x172.7.15.101:80 aaa.com -I
HTTP/1.1 403 Forbidden
Date: Tue, 29 Sep 2015 10:49:21 GMT
Server: Apache/2.2.16 (Unix) PHP/5.3.10
Content-Type: text/html; charset=iso-8859-1
# curl -x172.7.15.101:80 bbb.com -I
HTTP/1.1 301 Moved Permanently
Date: Tue, 29 Sep 2015 10:49:26 GMT
Server: Apache/2.2.16 (Unix) PHP/5.3.10
Location: http://aaa.com/
Content-Type: text/html; charset=iso-8859-1
此时可能会怀疑,访问控制的位置是在下面,所以调换位置:
- DocumentRoot "/usr/local/apache2/docs/aaa.com"
- ServerName aaa.com
- ServerAlias bbb.com
- Order deny,allow
- Deny from all
- Allow from 127.0.0.1
- RewriteEngine on
- RewriteCond %{HTTP_HOST} ^bbb.com$
- RewriteRule ^/(.*)$ http://aaa.com/$1 [R=301,L]
DocumentRoot "/usr/local/apache2/docs/aaa.com"
ServerName aaa.com
ServerAlias bbb.com
Order deny,allow
Deny from all
Allow from 127.0.0.1
RewriteEngine on
RewriteCond %{HTTP_HOST} ^bbb.com$
RewriteRule ^/(.*)$ http://aaa.com/$1 [R=301,L]
一样的效果。 所以得出结论。
结论: 301跳转优先级会高于访问控制!
编辑回复