skip to Main Content

Currently I have my search page hosted like below

mywebsite.com/search.html?query=cat

So I am extracting query from url parameter as you can see the query is 'cat' for now.

For some seo reasons this is not a good practice so I want to replace above format to following format:

mywebsite.com/search/cat

Is there any way to achieve such result without actually changing the current files? Right now I am hosting the website with nginx in ubuntu server. Any suggestion is hugely appreciated.

Thanks in advance

2

Answers


  1. There are thousands of examples for this in SO.

    Nevertheless here is a suggestion:

    RewriteEngine on 
    
    RewriteRule ^/?search/(.+)/?$ /search.html?query=cat [END,QSA]
    
    RewriteCond ${QUERY_STRING} (^|&)query=(.*)(&|$)
    RewriteRule ^/?search.html$ /search/%1 [R=301]
    
    Login or Signup to reply.
  2. You can simply do the following rewrite in your NGINX configuration (in server {...} block):

    rewrite ^/search/(.*)$ /search.html?query=$1 last;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search