asd
asd

Reputation: 138

.htaccess RewriteRule with 3 Get parameters

I will user .htaccess file to redirect

http://www.example.org/results.php?q=anything&start=0&type=web

to

http://www.example.org/search/anything/0/web

Is that possible ? At this time, i redirect only the q-GET parameter, with this RewriteRule:

RewriteRule ^search/(.*)$ results.php?q=$1 [L,QSA]

It still working, but i dont have any idea to rewrite 3 Get-parameters.

Upvotes: 0

Views: 493

Answers (2)

Luca Filosofi
Luca Filosofi

Reputation: 31173

RewriteRule ^(search)/(.*)/(\d+)/(.*)$ results.php?q=$2&start=$3&type=$4 [L,QSA]

little explanation:

when you regex-match with (.*) then you can get the matched portion with $#where # is an incremental number that represent the position of each single match in the chain.

  • search/(.*) = search/$1
  • search/(.*)/(.*) = search/$1/$2
  • search/(.*)/(.*)/(.*) = search/$1/$2/$3

Upvotes: 0

Peter
Peter

Reputation: 16915

RewriteRule ^search/(.*)/(.*)/(.*)$ results.php?q=$1&start=$2&type=$3 [L,QSA]

Upvotes: 1

Related Questions