0

I have following url:

www.example.com/profile?id=31

And I want to redirect it to :

www.example.com/profile/id/31

How can I do this ??

I tried using this:

RewriteCond %{QUERY_STRING} (^|&)id=31($|&)
RewriteRule ^www\.example\.com/profile$ /www.example.com/profile/id/31?&%{QUERY_STRING}

But it is not working

2 Answers2

0

I will go for something like this let me know if it helps:

RewriteRule ^ profile/([0-9]+)/?$ /profile?id=$1 [NC,L,QSA]

what it does is explained widely in https://stackoverflow.com/a/20566547/6517383 and other answers in this post.

Black Mamba
  • 8,408
  • 4
  • 52
  • 84
0

Try with below,

RewriteCond %{QUERY_STRING} ^(.+)=(.+)
RewriteRule ^(.+)$ http://www.example.com/$1/$2/$3 [R=301,L,QSD]

I am using match groups so it will work for any value for given similar pattern.

Abhishek Gurjar
  • 7,152
  • 9
  • 35
  • 40