skip to Main Content

I have a search form using GET request. When I hit enter, the url is as usual not SEO friendly, is there a way in which I can make it display SEO friendly urls when entered?

Eg.

GET Request http://someurl.com?a=search&query=what+are+you+looking+for
SEO URL should be http://someurl.com/search/what+are+you+looking+for

I already created a rule

RewriteRule ^search/(w+) index.php?a=search&query=$1

in my .htaccess that works when I manually type the SEO Url into the address bar. So I guess it’s only a matter of making sure when I hit enter inside the search field, it loads the SEO Url instead of the other.

3

Answers


  1. You can use this in your .htaccess:

    RewriteEngine On
    RewriteRule ^([^/]*)/([^/]*)$ /?a=$1&query=$2 [L]
    

    This will leave you with the URL:

    http://someurl.com/search/what+are+you+looking+for

    Login or Signup to reply.
  2. You have to redirect your orignal uri to the new uri , add the followng before your existing rule :

    RewriteEngine on
    RewriteCond %{THE_REQUEST} /(?:index.php)??a=search&query=(.+)sHTTP [NC]
    RewriteRule ^ /search/%1? [NE,L,R]
    
    Login or Signup to reply.
  3. I do this on my way 🙂

    This is the form for search

      <form method="post">
         <input type="text" name="search" placeholder="search"/>
      </form>
    

    Before form

    if(isset($_POST['search'])){
    echo '<script>window.location = "www.domain.com/search/'.$_POST['search'].'"</script>';
    }
    

    And in .htaccess

    RewriteEngine on
    RewriteRule ^search/([^/]*)$ index.php?page=search&search=$1 [NC,L]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search