I have two domains that point to the same root folder of my webspace. My root directory is setup like so:
- /domain1
- /domain2
- /shared
Where requests to...
- http://www.domain1.com/* should do an internal redirect to http://www.domain1.com/domain1/*
- http://www.domain2.com/* should do an internal redirect to http://www.domain2.com/domain2/*
- http://www.domain1.com/shared/* or http://www.domain2.com/shared/* should not be redirected and should server from the /shared folder
Current .htaccess:
# Redirect domain1.com paths to domain1 folder.
RewriteCond %{HTTP_HOST} ^www\.domain1\.com$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/domain1/
RewriteRule ^(.*)$ /domain1/$1
# Redirect controllers to index.php.
RewriteCond %{HTTP_HOST} ^www\.domain1\.com$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^domain1/(.*)$ /domain1/index.php?controller=$1 [QSA,L]
# Redirect domain2.com paths to domain2 folder.
RewriteCond %{HTTP_HOST} ^www\.domain2\.com$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/domain2/
RewriteRule ^(.*)$ /domain2/$1
# Redirect controllers to index.php.
RewriteCond %{HTTP_HOST} ^www\.domain2\.com$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^domain2/(.*)$ /domain2/index.php?controller=$1 [QSA,L]
What's remaining to do is:
- Don't serve pages from http://www.domain1.com/domain1 if the user types this in manually.
- Don't serve pages from http://www.domain1.com/domain2 if the user types this in manually (I've already implemented this but omitted it for brevity).
Note: I would rather not use symlinks since I run xampp on windows for local development.
My question is:
How can I redirect internally from http://www.domain1.com to http://www.domain1.com/domain1 but not serve http://www.domain1.com/domain1 if it is typed in by the user?