Sinros
Sinros

Reputation: 181

htaccess redirect dynamic get request

I need to REDIRECT (not just rewrite) from:

example.com/home/?s=keyword

to:

example.com/search/keyword

Currently I am trying to use the following:

RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^/?$ "http\:\/\/www\.example\.com\/home\/" [R=301,L]

RewriteCond %{QUERY_STRING} ^/s=(.*)$
RewriteRule ^(.*?)$ search/$1 [NC,R,L]

I know it is wrong but I have no idea how to fix it...

Upvotes: 0

Views: 47

Answers (1)

Jon Lin
Jon Lin

Reputation: 143876

try:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteRule ^/?$ http://www.example.com/home/ [R=301,L]

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

RewriteRule ^search/(.+)$ /home/?s=$1 [L]

Upvotes: 1

Related Questions