2013-12-09 21 views
1

一些正則表達式/ htaccess嚮導可以幫助嗎?我在找重寫規則即會.htaccess使用查詢參數重寫代理

  • 支持子域
  • 通過代理服務器(而不是301)
  • 通沿任意數量的查詢參數(如果存在的話)

行爲這樣,這個代理到:

  • www.domain.com - > www.otherdomain.com
  • dev.domain.com - > dev.otherdomain.com
  • www.domain.com?thing=123 - > www.otherdomain.com?thing=123
  • dev.domain.com?thing=123 & otherthing = ABC - > dev.otherdomain.com?thing=123 & otherthing = ABC

擁抱

+2

您是否在'www.domain.com'和'dev.domain.com'上啓用了'mod_proxy'? – anubhava

+0

我們有其他的代理規則可以工作。域的DNS解析爲其他域的IP。 – folktrash

回答

0

假設mod_proxywww.domain.comdev.domain.com啓用和兩個結構域使用的是S AME DOCUMENT_ROOT

將這個代碼在你DOCUMENT_ROOT/.htaccess文件:

RewriteEngine On 

RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC] 
RewriteRule^http://otherdomain.com%{REQUEST_URI} [P,L,NE] 

RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com$ [NC] 
RewriteRule^http://%1.otherdomain.com%{REQUEST_URI} [P,L,NE] 

QUERY_STRING自動結轉到新的目的地。

+0

哦,看起來很有希望。除了www&dev(還有qa和staging)之外,還有其他更多的東西。 ? – folktrash

+0

確定現在檢查更新的代碼。 – anubhava

+0

哦!檢查... – folktrash