I can point subdomains to subfolders, but not sub-subfolders. How can I?
Code:
RewriteEngine on
# Rewrite <subdomain>.example.com/<path> to example.com/<subdomain>/<path>
#
# Skip rewrite if no hostname or if subdomain is www
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\. [NC]
# Extract (required) subdomain (%1), and first path element (%3), discard port number if present (%2)
RewriteCond %{HTTP_HOST}<>%{REQUEST_URI} ^([^.]+)\.hostingz\.org(:80)?<>/([^/]*) [NC]
# Rewrite only when subdomain not equal to first path element (prevents mod_rewrite recursion)
RewriteCond %1<>%3 !^(.*)<>\1$ [NC]
# Rewrite to /subdomain/path
RewriteRule ^(.*) /%1/$1 [L]
What that code does is redirect
http://subdomain.hostingz.org to
http://hostingz.org/subdomain. And it works!
But how do I modify the last line, the RewriteRule so that it redirects to sites/(then the subdomain).
So
http://subdomain.hostingz.org -->
http://hostingz.org/sites/subdomain.
How can it be done? And test it out first as the examples below do not work.
Code:
RewriteRule sites/^(.*) /%1/$1 [L]
or
Code:
RewriteRule sites^(.*) /sites/%1/$1 [L]
Code:
RewriteRule ^(.*) /sites/%1/$1 [L]