2011-10-28 34 views
1

我需要修改一些通過Squid傳遞的特殊URL,例如:我通過我的Squid訪問地址www.google.com.vn。我想在某處將Squid源代碼修改爲將www.google.com.vn替換爲www.google.com。所以每次請求www.google.com.vn將成爲請求www.google.comSquid的URL修改/重寫

請幫ASPS

回答

3

首先,魷魚重寫和重定向依賴於第三方的幫手。 最好的部分是,你可以寫這個幫手任何編程語言

在squid.conf 中使用url_rewrite_program指令並添加到您的自定義腳本的路徑。 你的腳本將接收內容有以下幾點:

URL client_ip "/" fqdn user method [ kvpairs]\n

顯然你需要的URL部分,這樣算起來一種方式來獲得的URL部分,並返回你希望客戶端被定向到該網站。

希望以任何方式幫助...

例改寫PROGRAMM(C++)

#include <iostream> 
#include <string> 
using namespace std; 
// a replace function :) 
bool replace(std::string& str, const std::string& from, const std::string& to) { 
size_t start_pos = str.find(from); 
if(start_pos == std::string::npos) 
    return false; 
str.replace(start_pos, from.length(), to); 
return true; 
} 


int main() 
{ 
    while(1) 
    { 
     string input; 
     cin >> input; 
     replace(input, "www.google.vn", "www.google.com"); 
     cout << input << endl; 
    } 

}