To summarize, you want:
- There is a special case: If an url starts with /basic/api, you want it to go to the router.php page
- By default, an url that isn't a file should be searched for in public.
In addition you can redirect requests that go to /basic/public/something to /basic/something
Put this in a file .htaccess in the basic folder:
RewriteEngine On
RewriteBase /preview/
#Special case: api requests
RewriteRule ^api/ app/router.php [L]
#Default case: all public files
#Alternativelly use RewriteCond %{REQUEST_URI} !/basic/public
RewriteCond %{REQUEST_URI} !/public/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ public/$1 [L]
#Optionally prevent both localhost/basic/public/file and localhost/basic/file
#outputting the same
#Using THE_REQUEST trick to only match external requests
RewriteCond %{THE_REQUEST} ^(POST|GET)\ /basic/public/
RewriteRule ^public/(.*)$ $1 [R,L]
This will do the following:
localhost/basic/api/user/something
gets internally rewritten to localhost/basic/app/router.php
localhost/basic/something
gets internally rewritten to localhost/basic/public/something
localhost/basic/public/something
gets externally redirected to localhost/basic/something
(and is then internally rewritten)
Screencast of behaviour: http://www.screenr.com/9GUN