I have 3 sites/domains sharing the same web space, each site in its own subdirectory on the web root. Like so:
wwwroot/domain1/
wwwroot/domain2/
wwwroot/domain3/
By default, all domains directed/connected to the root, and there is no way to change this by my host provider, unbelievably, so I have to use this setup in .htaccess for the root directory:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^[www.]*domain1.com$ [NC]
RewriteCond %{REQUEST_URI} !^/domain1/.*
RewriteRule ^(.*) /domain1/$1 [L]
RewriteCond %{HTTP_HOST} ^[www.]*domain2.com$ [NC]
RewriteCond %{REQUEST_URI} !^/domain2/.*
RewriteRule ^(.*) /domain2/$1 [L]
RewriteCond %{HTTP_HOST} ^[www.]*domain3.com$ [NC]
RewriteCond %{REQUEST_URI} !^/domain3/.*
RewriteRule ^(.*) /domain3/$1 [L]
This redirects domains to their subfolders/sites.
I also want to have extensionless urls, forced www and no index-files or trailing slashes on each site, so I use the following setup for each subdirectory/domain, example from domain1:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
# Force www
RewriteCond %{HTTP_HOST} ^(domain1\.fi)$ [NC]
RewriteRule ^(.*)$ [
%1%{REQUEST_URI}...] [R=301,L]
# Redirect to remove /index.shtmlfiles.
RewriteCond %{THE_REQUEST} \ /(.+/)?index\.shtml(\?.*)?\ [NC]
RewriteRule ^(.+/)?index\.shtml$ /%1 [NC,R=301,L]
# Redirect direct client request for old URL with .shtml extension
# to new extensionless URL if the .shtml file exists
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/\ ]+/)*[^.\ ]+\.shtml\ HTTP/
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(([^/]+/)*[^.]+)\.shtml$ [
domain1.fi...] [R=301,L]
# Redirect any request for a URL with a trailing slash to extensionless URL
# without a trailing slash unless it is a request for an existing directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ [
domain1.fi...] [R=301,L]
# Internally rewrite extensionless URL request
# to .shtml file if the .shtml file exists
RewriteCond %{REQUEST_FILENAME}.shtml -f
RewriteRule ^(([^/]+/)*[^./]+)$ /$1.shtml [L]
All this works fine, except if I write "www.domain1.com/domain2" on the address bar, it leads to domain2-site, but the url won't change to "www.domain2.com". Also it is somehow possible to have "www.domain1.com/domain1" on the address bar also, while on domain1-site.
I want all the sites to appear separate to the user, there should be no possibility to have this kind of urls which indicate the opposite. How can this be achieved, what's wrong with my setup?