Beebee
Beebee

Reputation: 160

mod_rewrite from querystring to path

I'm trying to rewrite the following URL:

http://www.example.com/services/user/get.json?(name)=(username)&token=abcdef

To:

http://www.example.com/services/user/(name)/(username).json?token=abcdef

The querystring variable's label name goes after /user/, then followed by the querystring variable name's value username. Then token querystring variable should stay as it is.

So far I've come up with:

RewriteRule ^/services/user/get\.json\?([name])=([^&]+)&(.+)$ /services/user/$1/$2?$3

I'm quite bad at regex, and I'm not sure what I'm doing wrong here. If someone can help me out will be much appreciated.

Upvotes: 0

Views: 39

Answers (1)

Pilou
Pilou

Reputation: 1478

You can catch your arguments with a RewriteCond, and after replace your url.

So you can try this :

RewriteCond %{QUERY_STRING} ^([^=]+)=([^&]+)&(.+)$
RewriteRule ^services/user/get.json /services/user/%1/%2.json?%3 [R=301,L]

Upvotes: 1

Related Questions