You're missing a space somewhere in those rules, but I think you've got the right idea in making 2 separate rules. The harder problem is converting all the -
to spaces. Let's start with the conversion to GET variables:
# check that the "sue.php" actually exists:
RewriteCond %{REQUEST_URI} ^/([a-zA-Z0-9]+)/([^/]+)/?$
RewriteCond %{DOCUMENT_ROOT}/%1.php -f
RewriteRule ^([a-zA-Z0-9]+)/([^/]+)/?$ /$1.php?r=$2 [L,QSA]
RewriteCond %{REQUEST_URI} ^/([a-zA-Z0-9]+)/([^/]+)/([^/]+)/?$
RewriteCond %{DOCUMENT_ROOT}/%1.php -f
RewriteRule ^([a-zA-Z0-9]+)/([^/]+)/([^/]+)/?$ /$1.php?r=$2&c=$3 [L,QSA]
Those will take a URI that looks like /sue/blah/
and:
- Extract the
sue
part - Check that
/document_root/sue.php
actually exists - rewrite
/sue/blah/
to/sue.php?r=blah
Same thing applies to 2 word URI's
Something like /kevin/foo/bar/
:
- Extract the
kevin
part - Check that
/document_root/kevin.php
actually exists 3 rewrite/kevin/foo/bar/
to/kevin.php?r=foo&c=bar
Now, to get rid of the "-" and change them to spaces:
RewriteCond %{QUERY_STRING} ^(.*)(c|r)=([^&]+)-(.*)$
RewriteRule ^(.*)$ /$1?%1%2=%3\ %4 [L]
This looks a little messy but the condition matches the query string, looks for a c=
or r=
in the query string, matches against a -
in the value of a c=
or r=
, then rewrites the query string to replace the -
with a (note that the space gets encoded as a
%20
). This will remove all the -
instances in the values of the GET parameters c
and r
and replace them with a space.