skip to Main Content

I am trying to convert my URL in to SEO Friendly url. I do not have much knowledge about htaccess rewrite rules, URL is:

https://www.zesteve.com/search.php?loc=Guntur&q=manjunath-cake-shop

the URL should be

https://www.zesteve.com/Guntur/manjunath-cake-shop

I have tried this:

RewriteEngine On  
RewriteCond $1 ^search 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ search.php?q=$1 [L,QSA]

I got the result as

https://www.zesteve.com/search?loc=Guntur&q=manjunath-cake-shop

Edit

I am using jquery to redirect

 window.location.href = 'search?loc=' + location[0] + '&q='+ search_term;

3

Answers


  1. Chosen as BEST ANSWER

    If any body look for same solution. Here is my answer

    First it should redirect and convert to SEO Friendly URL

    # Redirect to SEO Friendly Url
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}s/+(?:search.php)??loc=([^s]+)&q=([^s]+)? [NC]
    RewriteRule ^ /%1/%2? [R=301]
    

    and now Set URL

    RewriteCond $1 ^ 
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ search.php?loc=$1&q=$2 [L,QSA]
    

    It solved my problem.

    https://www.zesteve.com/search.php?loc=Guntur&q=manjunath-cake-shop
    

    above URL is now

    https://www.zesteve.com/Guntur/manjunath-cake-shop
    

    I don't want to show search.php page in URL


  2. RewriteRule ^([^/]*)/([^/]*)$ /search.php?loc=$1&q=$2 [L]
    
    Login or Signup to reply.
  3. Use this in your .htaccess file:

    RewriteEngine On
    RewriteRule ^([^/]*)/([^/]*)$ /search.php?loc=$1&q=$2 [L]
    

    It will leave you with the URL: https://www.zesteve.com/Guntur/manjunath-cake-shop. Just make sure you clear your cache before you test this.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search