I am looking for correct htaccess rules for my search.php page. Because I tried several, but nothing worked. It may be possible my existing htaccess rules conflicting it. So I am also pasting my current htaccess file here. Currently I have following search page url with query string:
http://my-domain.com/search.php?q=keyword
I want the following clean url:
http://my-domain.com/search/keyword
My HTML form is:
<form method="get" action="search.php">
<input type="text" name="q" class="txtfield" value="<?php echo $q; ?>" placeholder="Search post here..." />
</form>
htaccess:
Options +FollowSymlinks -MultiViews
RewriteBase /
#Enable mod rewrite
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ page.php?category=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/([^/]+)$ page.php?category=$1&post=$2 [QSA,L]
Note that I don't have search related htaccess rule in above file because as I said nothing worked. I always saw 404 page. That's why I removed it.
Also If I put submit button in the form in some future like below:
<form method="get" action="search.php">
<input type="text" name="q" class="txtfield" value="<?php echo $q; ?>" placeholder="Search post here..." />
<input type="submit" name="btnsearch" class="btn" value="Search" />
</form>
My search url will change to:
http://my-domain.com/search.php?q=keyword&btnsearch=Search
Then I am wondering what correction/modification I will have to do in the correct htaccess rule which you will give to me as per my first query? Should we have two rules if the search url contains two or more than two query strings? Please help me on this guys. Thanks.