Reputation: 1118
I have some domains:
http://domainmain.com
http://domainone.com
http://domaintwo.com
My secondary domains are currently hosted under the main domain. No sub-directories, no other paths. So every domain get the contents of http://domainmain.com
.
For better understanding: These files points all to the same file: http://domainmain.com/index.php
, http://domainone.com/index.php
, http://domaintwo.com/index.php
.
For every domain I have a folder located at http://domainmain.com
:
domainname folder / path
-------------- -----------
domainmain.com /
domainone.com /domainone
domaintwo.com /domaintwo
My goal is to redirect every domain to the corresponding dir / path http://domainone.com
.
For example: http://domainone.com
has to show the content of path /domainone
. The visiter has to see http://domainone.com
. This also should work: http://domaintwo.com/images
shows http://domainmain.com/images
.
Some code I started with in the .htaccess
file:
RewriteCond %{HTTP_HOST} domainone.com [NC]
RewriteCond %{REQUEST_URI} !^/domainone
RewriteRule ^(.*)$ /domainone/$1 [NC,L]
And some PHP (but I want to use redirect instead of file_get_contents()
:
if ($_SERVER['SERVER_NAME'] == 'domaintwo.com') {
echo file_get_contents('http://domainmain.com/domaintwo');
die();
}
Note: It is only possible to have an .htaccess
file at http://domainmain.com
. My server runs PHP5.
Upvotes: 0
Views: 1177
Reputation: 785551
Enable mod_rewrite and .htaccess through httpd.conf
and then put this code in your .htaccess
under DOCUMENT_ROOT
directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(domainone)\.com$ [NC]
RewriteRule (?!^domainone(/.*|)$)^.*$ /%1%{REQUEST_URI} [NC,L]
RewriteCond %{HTTP_HOST} ^(domaintwo)\.com$ [NC]
RewriteRule (?!^domaintwo(/.*|)$)^.*$ /%1%{REQUEST_URI} [NC,L]
Upvotes: 0
Reputation: 772
Your question is quite similar to this one asked on the web-master's section;
How to redirect different domains to separate subdirectories.
Upvotes: 1