【发布时间】:2025-12-01 01:40:01
【问题描述】:
我在 tomcat(6) 前面有一个 apache (2.4.6) 服务器。我希望对 www.domain.com 的所有请求都永久重定向到 domain.com。我目前的配置是:
<VirtualHost *:80>
ServerName www.domain.ma
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain\.ma
RewriteRule ^(.*)$ http://www.domain.ma/$1 [R=permanent,L]
DocumentRoot /var/www/domain.ma/htdocs
ProxyRequests Off
ProxyPreserveHost On
ProxyPassReverseCookiePath /portal /
ProxyPass /portal/index.htm http://127.0.0.1:8080/portal/index.htm
ProxyPass /images !
ExpiresByType image/* A2592000
</VirtualHost>
当我请求 http://domain.ma/ 时,apache 不会重定向到 http://www.domain.ma/,有人可以告诉我我的配置文件有什么问题吗?
【问题讨论】:
-
请注意,您的 http_host 正则表达式并不完全正确。如果有人设法将
domain.masite.example.com指向您的服务器,您仍然会重定向,因为您只匹配主机名的开头,而不是整个字符串。
标签: tomcat mod-rewrite apache2 virtualhost