-1

I am using jquery to send the data to another page. But the url is not look good, so I want to make it as SEO friendly URL.

Below is my script:

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

Now my url is showing like:

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

But i want to like below:

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

I have no idea do I required to use .htaccess or any additional jquery?

LoicTheAztec
  • 184,753
  • 20
  • 224
  • 275
Asesha George
  • 1,820
  • 1
  • 24
  • 52

1 Answers1

2

You might do something like this:

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

Docs for .HTAccess
https://httpd.apache.org/docs/current/howto/htaccess.html

PHP Explode Function
http://php.net/manual/pt_BR/function.explode.php

Amit Verma
  • 38,175
  • 19
  • 80
  • 104
Victor H
  • 181
  • 1
  • 7
  • 1
    just now i got idea after seeing pretty url in google. its same as your answer. thank you. and i understand that i need to modify my window.location.href – Asesha George Apr 24 '16 at 05:25
  • 1
    i changed the code to window.location.href = 'search/' + location[0] + '/'+ query; then its worked thank you – Asesha George Apr 24 '16 at 05:56