It’s tricky to do this…
Requests for any other subfolder (assuming it exists) should go through to to the folder requested (e.g.
mydomain.com/proxy
ormydomain.com/shop
are passed through to their respective folders/proxy
and/shop
).
…in combination with…
Requests for subfolders which do not exist, should be routed through to
mydomain.com/site
…without losing the ability to pass rewrites onto said subfolders. You see, something like…
RewriteCond %{REQUEST_URI} ^/site
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) http://www.domain.com/site/$1 [R=301,L]
…will hijack any URL that does not resolve to an actual resource, even if the initial path component points to a valid subfolder. For example, /proxy/no-file-here
or /shop/product/dynamic-url
will all get redirected to /site/...
Since I assume that’s not ideal (particularly for Magento), I suggest a blacklist of directories to ignore, then handle the rest of your demands.
<IfModule mod_rewrite.c>
RewriteEngine on
# Enforce www, use lexical comparison for efficiency.
RewriteCond %{HTTP_HOST} != "www.domain.com"
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
# Stop rewriting for blacklisted directories
RewriteRule ^(proxy|shop) - [L]
# Handle root domain & non-"/site" requests
RewriteCond %{REQUEST_URI} = "https://wordpress.stackexchange.com/" [OR]
RewriteCond %{REQUEST_URI} !^/site
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) http://www.domain.com/site/$1 [R=301,L]
</IfModule>
# Legacy Joomla rules here
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /site/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /site/index.php [L]
</IfModule>
# END WordPress
I’m no Apache wiz, and although you’ve tried SO before, they still might be your best bet, if not even webmasters.