Forum Moderators: phranque
<form action='<?php echo get_home_link(); ?>buscar.php' method='GET'>
When I do a search I am sent to:
/buscar.php?params=search&q=query
but I would like to be sent to
/query.html
I have this .htaccess, but it doesn't redirect when I click the search button:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} ^(.*&)?params=search(&.*)?$ [NC]
RewriteCond %{QUERY_STRING} ^(.*&)?q=([^&]+)(&.*)?$ [NC]
RewriteRule ^buscar\.php$ /%2.html? [R=301,L]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteRule ^(.+)\.html$ buscar.php?q=$1¶ms=search [QSA,L]
can somebody help me?
Thank you in advance.
Gabriel
[edited by: jdMorgan at 2:42 pm (utc) on April 17, 2009]
[edit reason] Disabled graphic smilies in code. [/edit]
Let's say i put on the search field the word "bikes", I want to be redirected to bikes.html but really what it's doing is buscar.php?params=search&q=bikes
Sorry for my english, I hope you understand.
Thank you for your answer.
You should never link to a URL that you *know* will get redirected, since that requires your visitor's browsers (and search robots) to make two HTTP requests. And in this case, some browsers will throw scary-looking warnings that the form submission is being redirected, and some users may cancel at that point.
You can simplify your RewriteCond QUERY_STRING patterns. For example the second one can be simplified to
RewriteCond %{QUERY_STRING} &?q=([^&]+)&? [NC] Using this un-anchored pattern will actually result in faster processing, since it allows the query to be matched left-to-right, instead of starting at the right end and backing off one character at a time (due to the initial greedy ".*" subpattern.)
Jim
I think you are asking me to change the action on the form but I also think the search function is on buscar.php
Is there any way to do it with a similar htaccess code i put on OP?
Thank you again
Once the request for that "example.com/search/search+terms+go+here" URL arrives at your server, use mod_rewrite to internally rewrite it into a call to your buscar.php script, moving the "pieces" of the URL into the buscar.php query string:
"example.com/search/search+terms+go+here" --rewrite to--> "/buscar.php?params=search&q=search+terms+go+here"
RewriteRule ^search/(.+)$ /buscar.php?params=search&q=$1 [L]
For more information on this subject, see the thread Changing Dynamic URLs to Static URLs [webmasterworld.com] and other threads in our Apache Forum Library [webmasterworld.com].
Jim