You mentioned that two options are valid for you, so I'm using the second one, http://www.testdomain.com/john/2/doe
, and assuming a clean .htaccess
RewriteEngine On
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} ^name=([\w]+)\&id=([\d]{1,3})\&nick=([\w]+)$
RewriteRule .* /%1/%2/%3? [R=301,L]
The commented lines that check for files or directories may be uncommented depending on your situation, lets assume that a request on your site is going to be like this
http://www.example.com/test.php?name=john&id=2&nick=doe
If you have the file test.php
and you uncomment the line about checking for existing files, the rule I wrote will fail because of unmet conditions. If you don't have that file, you can uncomment the line. The same applies for directories, although safer since I don't think you have directories with extensions.
The above rules transform
http://www.example.com/test?name=john&id=2&nick=doe
into
http://www.example.com/john/2/doe
I tested it on a virtual server with Apache 2.2.25 on Linux.
Below is the rewrite log of the test in case you want to analyse it. The name of the folder and local virtual server where different, I hope I didn't alter anything important when renaming that information.
127.0.0.1 - - [28/Mar/2014:00:03:50 +0800] [www.example.com/sid#cee650][rid#7fe164002970/initial] (3) [perdir /mnt/webs/folder/] strip per-dir prefix: /mnt/webs/folder/test.php -> test.php
127.0.0.1 - - [28/Mar/2014:00:03:50 +0800] [www.example.com/sid#cee650][rid#7fe164002970/initial] (3) [perdir /mnt/webs/folder/] applying pattern '.*' to uri 'test.php'
127.0.0.1 - - [28/Mar/2014:00:03:50 +0800] [www.example.com/sid#cee650][rid#7fe164002970/initial] (2) [perdir /mnt/webs/folder/] rewrite 'test.php' -> '/john/2/doe?'
127.0.0.1 - - [28/Mar/2014:00:03:50 +0800] [www.example.com/sid#cee650][rid#7fe164002970/initial] (3) split uri=/john/2/doe? -> uri=/john/2/doe, args=<none>
127.0.0.1 - - [28/Mar/2014:00:03:50 +0800] [www.example.com/sid#cee650][rid#7fe164002970/initial] (2) [perdir /mnt/webs/folder/] explicitly forcing redirect with http://www.example.com/john/2/doe
127.0.0.1 - - [28/Mar/2014:00:03:50 +0800] [www.example.com/sid#cee650][rid#7fe164002970/initial] (1) [perdir /mnt/webs/folder/] escaping http://www.example.com/john/2/doe for redirect
127.0.0.1 - - [28/Mar/2014:00:03:50 +0800] [www.example.com/sid#cee650][rid#7fe164002970/initial] (1) [perdir /mnt/webs/folder/] redirect to http://www.example.com/john/2/doe [REDIRECT/301]
127.0.0.1 - - [28/Mar/2014:00:03:50 +0800] [www.example.com/sid#cee650][rid#7fe164006990/initial] (3) [perdir /mnt/webs/folder/] add path info postfix: /mnt/webs/folder/john -> /mnt/webs/folder/john/2/doe
127.0.0.1 - - [28/Mar/2014:00:03:50 +0800] [www.example.com/sid#cee650][rid#7fe164006990/initial] (3) [perdir /mnt/webs/folder/] strip per-dir prefix: /mnt/webs/folder/john/2/doe -> john/2/doe
127.0.0.1 - - [28/Mar/2014:00:03:50 +0800] [www.example.com/sid#cee650][rid#7fe164006990/initial] (3) [perdir /mnt/webs/folder/] applying pattern '.*' to uri 'john/2/doe'
127.0.0.1 - - [28/Mar/2014:00:03:50 +0800] [www.example.com/sid#cee650][rid#7fe164006990/initial] (1) [perdir /mnt/webs/folder/] pass through /mnt/webs/folder/john
Update according to your comment
If you want test on the final URL, use this:
RewriteRule .* /test/%1/%2/%3? [R=301,L]
If you want your index file, use this:
RewriteRule .* /index.php/%1/%2/%3? [R=301,L]
/test.php?...
, nottest.php?...
. #2 would seem to be the closest to "correct".