For my search engine, I have the page ...
/index.php?q=TERM
... which displays the search results.
Using mod_rewrite, I made it accessible via:
/q/TERM
The rule I used in the .htaccess was something like this:
RewriteEngine on
RewriteRule ^q/(.+)$ index.php?q=$1
This works well. But when I enter a term into my HTML form and click the submit button, I'm still redirected to ...
/index.php?q=TERM
How can I make my GET-fo开发者_开发问答rm directly calling the new and short URL? Its code is:
<form action="/index.php" method="get" accept-charset="utf-8">
...
</form>
A from will always call your page with ?q=TERM
and your rewrite rule only say : /q/TERM
is in fact ?q=TERM
Then you need to rewrite ?q=TERM
to /q/TERM first
. But we need to take care of loops.
So let's try :
EDIT1: other flags. (I found that [C] re run the rules, so we don't want that)
RewriteCond %{QUERY_STRING} ^q=(.*)$ [NC]
RewriteRule ^$ /q/%1 [NC,L]
RewriteRule ^q/(.+)$ index.php?q=$1 [NC,L]
Tell me how that behave.
Related: SO entry
精彩评论