2013-10-29 27 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 –

相關問題