Asesha George Asesha George - 6 months ago 5x
Javascript Question

how to convert a link to seo friendly url in jquery

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
// hide proposition list

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 shwoing like

but i want to like below

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


You might do something like this:


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


    $pathParts = explode('/', $_GET['path']);


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

Docs for .HTAccess

PHP Explode Function