Hm, I think g1 and I are editing in tandem Which should I be using
None of them. You simply cannot win if you have a literal space anywhere in an URL, whether in the body of the path or in the query string.
%2520 is especially lethal because it means the URL has gone through
two rounds of encoding: the first one to change the space into %20 and then a second one to change that leading % into %25. In real life you'll find this pattern in logs if you've got a locally based analytics program like piwik so there are double-nested query strings.
It doesn't have to stop there either. In my logs from a few months ago I find one building up to
%2525252525252525252525252525 252525252525252525252525252525 252525252525252525252520
with added real spaces for posting purposes It wasn't an evil robot, it was me testing a rule. Looks like Firefox let it go through 40 (forty!) iterations before it put its foot down. This strikes me as over-optimistic. (I have no idea what I was testing, but I kinda doubt I was seeing how many redirects the browser would permit.)
How do I remove the single apostrophe from the end?
Is it the end of the entire query string or just the end of that particular parameter? It's easier when it's at the very end because there aren't as many captures to juggle, but
:: don't cut & paste, I'm making this up as I go along ::
RewriteCond %{QUERY_STRING} ^([^']+)(?:'|%27)(&.+)?
RewriteRule (blahblah) http://www.example.com/$1?%1%2 [R=301,L]
The %27 may not be necessary. I can never remember what gets disencoded when :(
/sportsperson.php?sport=hky&name=Joe+Dude
/sportsperson.php?sport=fball&name=Harry+Lime
to these:
/sportsperson.php/Joe-Dude-hockey-player-profile
/sportsperson.php/Harry-Lime-football-player-profile
The significant part is
sport=(nameofgame)&name=(first)+(last)
which optimally would become
first-last-nameofgame-player-profile
assuming all your players have the goodness to have exactly two names ;)
If your query string uses abbreviations like "hky" or "fball" there will be more rules involved. Whether you can still do it in mod_rewrite alone will depend on just how many sports you cover. Three or four or six sports, no problem. But if you're talking about curling, jai alai and Australian Rules Football, it may be php-script time.