2009-08-28 24 views
2

我有這樣的重寫規則...重寫到新的域名?與網址查詢?不工作。 :(幫助

重定向從world.example.com到web.example.com

RewriteCond %{HTTP_HOST} ^world\.example\.com$ [NC] 
RewriteCond %{HTTP_HOST} !^$ 
RewriteCond %{SERVER_PORT} !^80$ 
RewriteRule ^(.*)$ https://web.example.com$1 [R=301,L] 

所有初始請求偉大的工程。不過,我的一些應用有...

https://world.example.com/approvals/?id=b47b5256567 

不幸的是,它沒有被正確地重定向到web.example.com。相反,它只是去web.example.com沒有查詢參數。

我怎樣才能使所有請求重定向到web.example.com以及查詢參數?

基本上,它應該做的......

https://world.example.com/approvals/?id=b47b5256567 
then 
https://web.example.com/approvals/?id=b47b5256567 

只是改變了世界的網絡並通過查詢字符串。

幫助

回答

5

您不需要使用複雜的重寫引擎來執行此操作。只需使用Redirect

<VirtualHost *> 
    ServerName world.example.com 
    Redirect permanent/https://web.example.com/ 
</VirtualHost> 

Redirect指令自動保存你什麼重定向在於這一切之後。

+0

很好。等一下,讓我試試。我應該關閉RewriteEngine嗎? – 2009-08-28 01:41:34

+0

Redirect指令不使用RewriteEngine,所以沒關係。 – 2009-08-28 01:51:45

+0

明白了!有效!但是,只有在http。如果使用https://world.example.com鏈接,則只會重定向到主頁面,而不會查詢h​​ttps://web.example.com。 不知道這是否可能只是我,但我的world.example.com(是一個自簽名證書),不知道這是否導致問題。 但總體而言 - 解決方案很容易。謝謝你。 – 2009-08-28 02:01:03

1

你忘了使用「查詢字符串附加」標誌[R=301,L,QSA]

+0

啊,但是重寫有點複雜。 – 2009-08-28 02:02:41

+0

嗯,我不這麼認爲。但是,如果您有權訪問服務器配置文件,則Greg Hewgill的建議更專業化。 – Havenard 2009-08-28 03:11:12

0

我們也可以用Nginx來實現。

server { 
    listen 80: 
    server_name: world.example.com  

    # URL redirect 
    #rewrite^http://web.example.com$request_uri? permanent; 
    rewrite^$scheme://web.example.com$request_uri permanent; 
    #rewrite^$scheme://web.example.com permanent; 
    #rewrite^$scheme://web.example.com; 
} 

參考: