views:

485

answers:

3

hello...

im trying to redirect "search.php?q=somethinghere" to "search/somethinghere/" but I can't do it! I'm trying to send form "<form action="search/" method="get" name="search">" like this but url goes to "search/?q=somethinghere"

RedirectMatch 301 ^/search.php?q=(.*)$ http://domain.com/search/$1/ this is also not working. whats the problem?

I don't want "?q=" in URL.

+2  A: 

Unless you have a typo above the problem is that you're trying to redirect:

^/search.php?q=(.*)$

but the URL you're receiving is:

search/?q=somethinghere

(the difference is the .php in your redirect rule)

You may want to try using the following redirect rule instead:

RedirectMatch 301 ^/search?q=(.*)$ http://domain.com/search/$1/
Austin Fitzpatrick
but i want to cut out "?q=" things.. understand?
Ronnie Chester Lynwood
Try this: RedirectMatch 301 ^/search/?q=(.*)$ http://domain.com/search/$1/The issue is that you're looking for something different than what you're getting. There's no ".php" in your request, so your rule is going to miss it.
Austin Fitzpatrick
its not worked. nothing happens
Ronnie Chester Lynwood
Sorry, looks like the something in my previous comment got eaten. I'll edit the post to include what I would recommend suggesting.
Austin Fitzpatrick
A: 

It would be much cleaner and faster to do it on the client side. Have Javascript construct the search/query URL on form submit - that will save you an extra request.

However, to do it through server-side redirects, you can use mod_rewrite with RewriteCond and QUERY_STRING as the source:

RewriteCond %{QUERY_STRING}  \bq=([^&]*)$
RewriteRule ^search.php$ /search/%1 [R=301]
Max Shawabkeh
this is working but URL in adress bar still search.php?q=sss
Ronnie Chester Lynwood
Make sure you use [R=301] to do a proper redirect including changing the URL. I edited that a minute after posting so you might have copied the older version.
Max Shawabkeh
with your updated code url becomes: http://domain.com/search/nero?q=nero "?q=" still here :((
Ronnie Chester Lynwood
A: 

Whenever I have .htaccess questions, I always take a look at this site first: http://corz.org/serv/tricks/htaccess2.php#cooldenial

The site provides a lot of examples and explanations for doing different things with .htaccess files. According to that site you could try something like:

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^search/([^/]+) http://domain.com/search.php?q=$1 [NC]

However, I'm not an .htaccess guru - so you may need to fiddle with it.

jeremysawesome