Domain Aliases and Mod_rewrite

Using a single web hosting account to host multiple sites

Domain Aliases and Mod_rewrite

Postby -=Mojo Will=- » Mon Feb 05, 2007 6:36 pm

Ok I have www.maindomain.com hosted at the moment have redirects from

www.domain1.com domain2.com etc forwarding tomaindomain.com/domain1/ etc using the redirect with the domain1.com addeis. touble is u goto domain1.com and get

http://www.maindomain.com/dopain1/blah/index.php etc

now domain1.com is adde to maindomain.com hosting as domain alias so it will accept connections on domain1.com if i cahnge the DNS entry for domain1.com

how do i get ti to firstly

if coming from ww.domain1.com goto maindomain.com/domain1/ BUT stil display as domain1,com/index.php??

I was told it was possible but they didnt know quite how
-=Mojo Will=-
 
Posts: 2
Joined: Mon Feb 05, 2007 6:31 pm

Postby richardk » Tue Feb 06, 2007 12:50 pm

In a .htaccess file in maindomain.com's document root:
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{DOCUMENT_ROOT}/domain1%{REQUEST_URI}/ -d
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(www\.)?(domain1|domain2)\.com$ [NC]
RewriteRule ^(.*)$ /domain1/$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby -=Mojo Will=- » Tue Feb 06, 2007 1:16 pm

richardk wrote:In a .htaccess file in maindomain.com's document root:
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{DOCUMENT_ROOT}/domain1%{REQUEST_URI}/ -d
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(www\.)?(domain1|domain2)\.com$ [NC]
RewriteRule ^(.*)$ /domain1/$1 [QSA,L]


hey thanks for replying any chance of you running through what the stuff does so that i kmow for next time.

also would that allow domain1.com to come to maindomain.com and go to maindomain.com/domain1 but display domain1.com/file.php AND allow domain2 to come to maindomain.com and do the same be forwarded to main.com/domain2/ with display altered as well

i would be forwarding the domains to the maindomain.com IP and not redirecting to URLs sorry if this is making NO sense I know what i mean
-=Mojo Will=-
 
Posts: 2
Joined: Mon Feb 05, 2007 6:31 pm

Postby richardk » Tue Feb 06, 2007 1:41 pm

AND allow domain2 to come to maindomain.com and do the same be forwarded to main.com/domain2/

You didn't ask for that.

Code: Select all
Options +FollowSymLinks

RewriteEngine On

# to stop mod_dir redirecting to the maindomain.com URL
# when you miss a trailing slash, add the missing slashes
RewriteCond %{DOCUMENT_ROOT}/domain1%{REQUEST_URI}/ -d [OR]
RewriteCond %{DOCUMENT_ROOT}/domain2%{REQUEST_URI}/ -d
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]

# as long as it's not a sub request (to stop loops)
RewriteCond %{ENV:REDIRECT_STATUS} ^$
# match the domain name
RewriteCond %{HTTP_HOST} ^(www\.)?(domain1|domain2)\.com$ [NC]
# add it as the first directory and rewrite
RewriteRule ^(.*)$ /%2/$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 45 guests

cron