Reputation: 2943
I use lunarpages for my hosting, and can have multiple websites added on. When I add a new website, it creates a directory in where my current site exists
ie my site is jeffkilroy.com, if I make a domain for hello.com, it now also exists at jeffkilroy.com/hello
This is fine except I would like to organize it a bit better so that the site directories don't mix with my jeffkilroy.com files
If I put all my jeffkilroy.com site files in something called "main", Is it possible to put something in htaccess where:
jeffkilroy.com/home really goes to jeffkilroy.com/main/home
but still be able to easily access my stuff from the root (other sites): jeffkilroy.com/hello
Upvotes: 0
Views: 199
Reputation: 19169
This solution is entirely dependent on you not having folders in your root (for the other sites) that are named the same as folders in your main site, but since you still want to be able to access the other sites' folders from the root, there's not much way around that.
Anyway, this seems to work:
RewriteEngine On
# Let's prevent them from being able to go to our /main path manually
RewriteCond %{THE_REQUEST} ^(POST|GET)\s/main
RewriteRule ^main/?(.*)$ http://jeffkilroy.com/$1 [R,L]
# Redirect stuff to /main/ if it isn't pointing to something else, or
# if it's just pointing to the primary root
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^.*$ /main/$0
RewriteCond %{REQUEST_URI} !-f
RewriteCond /main%{REQUEST_URI} -f
RewriteRule ^.*$ /main/$0
RewriteCond %{REQUEST_URI} !-d
RewriteCond /main%{REQUEST_URI} -d
RewriteRule ^.*$ /main/$0 [L]
Side note for the curious: It would be nice to be able to condense the RewriteCond
statements by using the [OR]
flag, but there is no operator precedence, so it's just evaluated top-to-bottom, which wouldn't work here.
Upvotes: 1