.htaccess - silently rewrite/redirect everything to internal subfolder

Same idea as @guido suggested, but a bit shortened using negative lookahead

RewriteEngine On
RewriteRule ^(?!site/)(.*)$ site/$1 [L]

Note: I am not using QSA flag as we are not adding additional parameters to the query string for the replacement URL. By default, Apache will pass the original query string along with the replacement URL.

http://www.example.com/index.php?one=1&two=2 

will be internally rewritten as

http://www.example.com/site/index.php?one=1&two=2

If you really want add a special parameter (ex: mode=rewrite) in the query string for every rewrite, then you can use the QSA Query String Append flag

RewriteEngine On
RewriteRule ^(?!site/)(.*)$ site/$1?mode=rewrite [L,QSA]

Then this will combine mode=rewrite with original query string

http://www.example.com/index.php?one=1&two=2 

to

http://www.example.com/site/index.php?mode=rewrite&one=1&two=2 

RewriteEngine On

RewriteRule ^(.*)$ site/index.php?var=$1 [L]

With this rule, i'm passing all requests to site/index.php, so you could get the requested uri via $_GET['var'], and then you'll make the index.php serve the requested url behind the scene without the url changing in the user's browser. Ciao.


You need to capture the url request incoming into the server, like this:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/site/
RewriteRule ^(.*)$ /site/$1 [L,QSA]

The QSA is (eventually) to also append the query string to the rewritten url