2013-10-29 29 views
0

目前,我在我的httpd.conf文件下面的规则从端口80上的所有请求转发到端口8080通过GlassFish应用服务器提供服务:如何将请求转发到另一个URL?

<VirtualHost *:80> 
    ServerAdmin [email protected] 
    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的写作规则的总noob。因此,如果你能告诉我我在这里做错了什么,我将非常感激:)。

UPDATE:

以下规则完美的作品:

RewriteEngine On 
RewriteRule ^/$ /page/index.html [R] 

回答

1

您需要添加一个$表示URI的末尾:

RewriteEngine On 
RewriteRule ^/$ http://myserver.com/page/index.html 

ProxyPass/http://localhost:8080/ 
ProxyPassReverse/http://localhost:8080/ 

没有$中,正则表达式^/匹配/page/index.html这将导致它重新直接再次,它会再次匹配,并再次重定向等。

+0

谢谢! :d –

相关问题