2014-01-17 113 views
0

所以我需要在這種情況下,我需要解析出proptype=rental和發送整個事情301重定向基於變量在POST

發送某些搜索帖子不同的網址...

www.xyz.com/search-results.php?city%5B%5D=Boynton+Beach&proptype=rental&foreclosure=&price_from=0&price_to=0&footage_from=&footage_to=&bedrooms_from=&bedrooms_to=&bathrooms_from=&bathrooms_to=&pets=&year_from=&year_to=&pool= 

www.xyzRentals.com/search-results.php?city%5B%5D=Boynton+Beach&proptype=rental&foreclosure=&price_from=0&price_to=0&footage_from=&footage_to=&bedrooms_from=&bedrooms_to=&bathrooms_from=&bathrooms_to=&pets=&year_from=&year_to=&pool= 

我知道我需要添加一些正則表達式來解析.htaccess文件中的url,並做一個301 ...任何快速的想法如何做到這一點?我試過

RedirectMatch 301 ^search-results.php?(.*)proptype=rental(.*)$ http://www.xyzRentals.com/search-results.php?$1proptype=rental$2 

,但沒有工作,我不知道爲什麼......當我把正則表達式爲匹配它說,它不匹配,但仍沒有重定向。

ANSWER

所以我最終做jQuery中......

var searchType = $('#proptype').val(); 

if (searchType == 'rental') { 
    $('#form').attr('action','http://www.floridaspropertymanagement.com/search-results.php'); 
} 
$('#form').submit(); 

回答

0

Quick'n'dirty

$str = 'www.xyz.com/search-results.php?city%5B%5D=Boynton+Beach&proptype=rental&foreclosure=&price_from=0&price_to=0&footage_from=&footage_to=&bedrooms_from=&bedrooms_to=&bathrooms_from=&bathrooms_to=&pets=&year_from=&year_to=&pool='; 

preg_match('/proptype=([^&]*)/i', $str, $matches); 
$host = ""; 
if (isset($matches[1])) { 
    switch ($matches[1]) { 
     case 'rental': 
     $host = 'www.xyzRentals.com'; 
    break; 
    } 
} 

$str=preg_replace('#([^\/]*)\/#i', $host . '/', $str); 


header("Location: $str"); 
+0

tyvm ...工作..我結束了在js做它 – menriquez

0

header("Location: [...]);發出了一個301 -

所以如果你的$ _POST變量總是要proptype =那麼,

header("Location: {$yourURLwithLotsOfGETparams}&proptype={$_POST['proptype']});

+0

嗯......好吧,試試這個試試... thxs! – menriquez