This question has been edited for clarification:
I am trying to create "pretty URLs" that should disguise themselves as follows:
mysite.com/index.php?p=1 ==> mysite.com/site_one/index.php
mysite.com/aboutus.php?p=2 ==> mysite.com/site_two/aboutus.php
mysite.com/anypage.php?p=3 ==> mysite.com/site_three/anypage.php
As you can see, mod_rewrite should simply convert the "p" variable into a predetermined pseudo-directory (this directory does not exists...this is just an aesthetic rewrite).
Obviously, this creates a complication. When a user visits mysite.com/site_one/index.php, there should be a background transfer to mysite.com/index.php?p=1. This background transfer results in a loop that causes a server error.
I have attempted to prevent this loop by using the following code:
RewriteCond %{QUERY_STRING} !NON=
RewriteCond %{QUERY_STRING} ^(.*[&?])?p=1([&].*)?$
RewriteRule ^/?(.*) /site_one/$1 [PT,L]
RewriteCond %{QUERY_STRING} !NON=
RewriteRule ^/?site_one/?(.*) /$1?NON=1&p=1 [PT,L]
Unfortunately, this still causes a server error. Can anyone see where the code has gone wrong?