开发者

how to use htaccess redirectmatch with query_string?

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 开发者_JS百科URL.


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/


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]


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜