hakki
hakki

Reputation: 6521

.htaccess RewriteRule with form parameter

www.example.com/Search.php?q=mySearchString this is my search link. I want to change it to

www.example.com/Search/mySearchString

Then I tried below rule in my .htaccess file but it looks like -> Search/?q=mySearchString How I can eliminate ?q= from address

in .htaccess file I add a rule like this;

RewriteRule ^Search/(.*)$ Search.php?q=$1 [L,NC]

Also I send search query with a form and form's method is 'GET'

 <form class="navbar-search pull-left" method="GET" action="Search/">
    <input name="q" type="text" />
 </form>

How can I fix it?

Upvotes: 0

Views: 840

Answers (1)

Jon
Jon

Reputation: 12992

If you rename your search input to:

<input name="query" type="text" />

Then use these two rules:

# If someone searches /Search/?query=search+string
RewriteCond %{QUERY_STRING} query=([^&]+)
# Redirect to /Search/search+string
RewriteRule ^Search/$ Search/%1 [L,R=301,NC]

# Match the redirect from the rule above and serve up results
RewriteRule ^Search/(.*)$ Search.php?q=$1 [L,NC]

Upvotes: 1

Related Questions