2015-07-20 68 views
0

我有以下用於縮短搜索引擎優化網址的代碼。用PHP搜索引擎優化的網址縮短

<?php 
function getURL($url){ 

    $urlGet = parse_url($url); 
    $queries = explode("&", $urlGet['query']); 
    $newURL = $urlGet['path']; 
    foreach($queries as $query) { 
     $queryContent = explode("=", $query); 
     $queryContent[0] == "Ad"? $newURL .= str_replace(" ", "-", $queryContent[1]):$newURL .= "/".$query; 

    } 
    return $newURL; 
    } 

    ?> 

當我點擊以下即時得到這個錯誤 未找到

的鏈接請求的URL/deffsale/AllAds /其他-Mobile的電話/平板電腦並沒有在此服務器上找到。

<a href="<?php echo getURL('AllAds/?Ad=Other Mobile Phones/Tablets'); ?>">Other Mobile Phones/Tablets</a><br> 

然而,點擊縮短的URL之前INTIAL鏈接,它的運作非常well.Im測試它在我的localhost.Please幫我解決這個問題

<a href="AllAds/?Ad=Other Mobile Phones/Tablets">Other Mobile Phones/Tablets</a><br> 

回答

0

鏈接指向的位置,你不能只是改變一個鏈接,並期望你的服務器神奇地發現它,只是因爲它看起來有點相似。你需要告訴你的服務器如何處理「seo url」,這通常是通過Apache mod_rewrite完成的。

+0

我真的在黑暗中進一步說明 –