0

Possible Duplicate:
Form Submit URL Formatting

I have simple form:

<form method="GET" action="http://{$smarty.server.SERVER_NAME}/recherche/">
        <input type="text" name="s" value="Recherche" class="text" id="searchbox" />
        <input type="submit" class="search" value="Rechercher !" title="Rechercher !" />
</form>

when I submit my form, the url brings me on:

http://mywebsite.com/recherche/?s=mysearch

but I rewrite the url properly like this:

# Recherche
RewriteRule ^recherche/([^/]*)$ /index.php?page=recherche&s=$1 [L]

but I do not know how to get on the right url (without the &s=) without redirection

Community
  • 1
  • 1
Julien
  • 1,946
  • 3
  • 33
  • 51

1 Answers1

1

Your rewrite rule: RewriteRule ^recherche/([^/]*)$ /index.php?page=recherche&s=$1 [L] only rewrites in one direction internally to the server. This rule has no affect whatsoever on the browser except what content is sent in response to a request that looks like /recherche/something. If you actually want the URL in the address bar to be changed, you need to respond with a redirect to the request, not internally do some URI mangling and return content. To do this you need:

RewriteCond %{THE_REQUEST} ^GET\ /recherche/\?s=([^&\ ]+)
RewriteRule ^recherche/$ /recherche/%1? [L,R=301]

And then you have your rule:

RewriteRule ^recherche/([^/]*)$ /index.php?page=recherche&s=$1 [L]

Both of them should work together. One redirects the browser to the URL without the query string, the other take the URL without the query string and internally rewrites it back to a query string.

Jon Lin
  • 142,182
  • 29
  • 220
  • 220
  • therefore, I am obliged to make a redirection! but it is more cleaner than a condition in php... Thanks Jon Lin =) – Julien Sep 27 '12 at 07:45