如何在jquery中将链接转换为seo友好URL

时间:2016-04-24 04:59:40

标签: javascript php jquery .htaccess seo

我正在使用jquery将数据发送到另一个页面。但是网址看起来不太好,所以我想把它作为SEO友好的URL。

以下是我的剧本:

function set_item(item) {
    // change input value
    $('#searchitem').val(item);
    // hide proposition list
    $('#search_list_id').hide();

     var location = $('#search_location').val().split(',');
     var search_term = $('#searchitem').val();
     var query =encodeURIComponent(search_term);

     if(search_term != '' && location !=''){
     window.location.href = 'search.php?location=' + location[0] + '&search_term='+ query;
     }
}

现在我的网址显示如下:

http://www.zesteve.com/search.php?location=Hyderabad&search_term=Traditions%20Events%20Management%20%26%20Marketing%20Pvt%20Ltd

但我想在下面说:

http://www.zesteve.com/search/Hyderabad/Traditions-Events-Management-&-Marketing-Pvt-Ltd

我不知道我是否需要使用.htaccess或任何其他jquery?

1 个答案:

答案 0 :(得分:2)

您可能会这样做:

htaccess的:

RewriteEngine on
RewriteRule ^search/(.+)$ /search.php?path=$1 [NC,L]

的search.php:

<?php
if(isset($_GET['path']))
{
    $pathParts = explode('/', $_GET['path']);

    var_dump($pathParts);

    echo "<br /><b>Location:</b> " . $pathParts[1];
    echo "<br /><b>Search Term:</b> " . $pathParts[2];
}   
?>

.HTAccess的文档
https://httpd.apache.org/docs/current/howto/htaccess.html

PHP爆炸功能
http://php.net/manual/pt_BR/function.explode.php