【发布时间】:2013-11-08 23:28:27
【问题描述】:
目前,我的 httpd.conf 文件中有以下规则,用于将所有请求从端口 80 转发到端口 8080,以由 GlassFish 应用服务器提供服务:
<VirtualHost *:80>
ServerAdmin admin@myserver.com
ServerName myserver.com
ProxyPreserveHost On
# setup the proxy
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
</VirtualHost>
现在,我需要添加一条规则,以便所有对http://myserver.com/ 的请求都将转发到http://myserver.com/page/index.html,并且该URL 在客户端浏览器上仍应显示为http://myserver.com/。我尝试在上面的VirtualHost中添加以下规则:
RewriteEngine On
RewriteRule http://myserver.com/ http://myserver.com/page/index.html
或
RewriteEngine On
RewriteRule ^/ http://myserver.com/page/index.html
或
RewriteEngine On
RewriteRule ^/index.html http://myserver.com/page/index.html
但是,当我转到http://myserver.com/ 时,浏览器出现此错误:This webpage has a redirect loop。只有转到http://myserver.com/index.html,第三条规则才有效。
我在为 Apache 编写规则方面完全是个菜鸟。因此,如果你能告诉我我在这里做错了什么,我将非常感激:)。
更新:
以下规则完美运行:
RewriteEngine On
RewriteRule ^/$ /page/index.html [R]
【问题讨论】:
标签: apache mod-rewrite url-rewriting forward rule