How to rewrite the url of a specific search?

29 Views Asked by At

I wish to rewrite the url of my search page result

Now is http://www.example.com/search/?location_name=Los+Angeles

and i want to do like that

http://www.example.com/search/LosAngeles

I want to get rid of ?, the location_name and if a city has two words, i don't want to separated by +, but shown as one.

Either in .htaccess or in functions.php

Update : My form is this

<form action="<?php echo esc_url(get_the_permalink($result_page)); ?>"  method="get" >

this goes to

http://www.example.com/search/?location_name=Los+Angeles

what if i add to form action onsubmit="return submitAction(this);"

What js i have to put so that the url goes to location_name value e.g. Los Angeles

http://www.example.com/search/LosAngeles
1

There are 1 best solutions below

0
M-CreeD On

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteRule ^results/([^/]+)/([^/]+)/?$ /search.php?search_query=$1&custom_title=$2 [L,NC,QSA]