用PHP缩短SEO的网址

时间:2015-07-20 08:15:22

标签: php

我有以下代码来缩短SEO的URL。

<?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;
    }

    ?>

当我点击下面的链接时,我收到此错误 找不到

在此服务器上找不到请求的网址/ deffsale / AllAds / Other-Mobile-Phones / Tablets。

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

但是,在缩短网址之前单击初始链接时,它运行得非常好。我在我的localhost上测试它。请帮我解决这个问题

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

1 个答案:

答案 0 :(得分:0)

链接指向位置,您只需更改链接并期望您的服务器神奇地找到它只是因为它看起来有点类似。您需要告诉您的服务器如何处理&#34; seo url&#34;,这通常是通过apache mod_rewrite完成的。