I am using one webserver for hosting two different websites, each having it's own domain and located in it's own subdirectory on the server. Both domains point to the root directory of my server.
This is my file structure:
root/
domain1/
domain2/
In my root directory i am using a small PHP script to determine which URL is coming in and than forward it to corresponding subdirectory.
if (($_SERVER['SERVER_NAME'] == "www.domain1.com" || $_SERVER['SERVER_NAME'] == "domain1.com") ) {
Header( "HTTP/1.1 301 Moved Permanently" );
header("location: http://www.domain1.com/domain1");
}
else if (($_SERVER['SERVER_NAME'] == "www.domain2.com" || $_SERVER['SERVER_NAME'] == "domain2.com") ) {
Header( "HTTP/1.1 301 Moved Permanently" );
header("location: http://www.domain2.com/domain2");
}
Up to here it works totally fine. When I call ww.domain1.com I get forwarded to the corresponding subdirecoty and the domain changes to www.domain1.com/domain1. This is where my question arrises: How can I hide the subdirectory in the URL? I have been struggeling with this for ages, reading guides to mod_rewrite and searching SO but didn't get anny success.
I have tested my server for RewriteEngine On, which works fine, I Just cant get the desired behaviour.
Edit:
Here is my htaccess code, located in the subdirectory domain1. The same code is located in directory2, changed to the naming conventions.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domain1.com$
RewriteRule !^domain1/ domain1%{REQUEST_URI} [L]
I got the idea for this from SO: SO Article
Thanks in advance ;)