2015-07-20 102 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

我真的在黑暗中进一步说明 –