hello there. I am trying to use rewrite mod for the url (htaccess) Everything is fine but i do not know what to do on search page. I am just using a form for the search like: <form name="form" id="form" action="http://www.site/search.php" method="get" enctype="multipart/form-data"> <table style="height:20px;"> <tr> <td width="218" style="height:20px;"><input class="input_1" type="text" name="q"></td> <td><input type="submit" name="Submit" value="Search" STYLE="width:6em; height:2em"></td> </tr> </table></form> PHP: I managed to get the htaccess for it which is: Options +FollowSymLinks RewriteEngine on RewriteRule search-q-(.*)-Submit-(.*)\.htm$ search.php?q=$1&Submit=$2 PHP: but i do not know how to change the search form according to this htaccess. Any idea? Thanks
Your htaccess and forms is correct, like if someone goes manually to http://www.site/search-q-test-Submit-Search.htm it will open your search page. but you need to automatically transfer your visitors to this url. For this, use below .htaccess code: RewriteCond %{QUERY_STRING} q=(.*)&Submit=(.*) RewriteRule search.php /search-q-%1-Submit-%2.htm? [R=301,L] RewriteRule search-q-(.*)-Submit-(.*).htm$ search.php?q=$1&Submit=$2 [L] Code (markup): It will automatically transfer your visitor from your Form page like http://www.site/search.php?q=test&Submit=Search to http://www.site/search-q-test-Submit-Search.htm Thanks, hope it helps!
what about if i want to do this http://www.site/search.php?q=test PHP: instead of this http://www.site/search.php?q=test&Submit=Search PHP: and if i change the htaccess code to RewriteRule search/q/(.*)/ search.php?q=$1 RewriteRule search/q/(.*) search.php?q=$1 PHP: What kind of htaccess i would need? Thank you very much.
ok.. I managed to get it working. I used: RewriteEngine on RewriteCond %{QUERY_STRING} q=(.*) RewriteRule search/%1? [R=301,L] RewriteRule search/(.*)$ search.php?q=$1 [L] PHP: the output is: http://www.site.com/search/xxxxx but i have got a problem. if there is second page for the search i do not know what to do. this is the php code for second page: <a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 >></a PHP: and this is the one for previous page: <a href=\"$PHP_SELF?s=$prevs&q=$var\"><< Prev 10</a> PHP: Thanks
The way I do this is to make an intermediate page called something like searchredirect.php: $SearchURL = $SiteRoot.'/search/'.$_GET ['q']; header("Location: $SearchURL"); /* Redirect browser to the new address */ Code (markup): Then you rewrite '/search/sausages' to '/search.php?q=sausages' in .htaccess. That makes it transparent to the user and creates pretty much the same effect. I just found it simpler. Maybe someone can see a disadvantage to this method..?
Maybe... what do other people think? I think redirecting pages within my own site for the purposes of rewriting them is my own business, not Google's... It's another matter if I was trying to cloak something. Anyway, I guess Google DOES index search results pages, and they can be a good source of "dynamic content", but they are not a priority anyway... As long as Google is not complaining about my "main" content pages.
For the normal search form i am not bodered about my urls. but i am using this search function as a tag clouds. My purpose in here is to get a nice url. I am linking certain keywords on the page.