Two URLs pointing to the same IP address. Any way to redir?

Using a single web hosting account to host multiple sites

Two URLs pointing to the same IP address. Any way to redir?

Postby YoDude9999 » Mon Jul 21, 2008 3:44 am

Hi I have two domain names, we'll say domain1.com and domain2.com.
Both of the DNS listings point to the same IP address, which is a single static address.

Is there a way to have users that come to the same IP address from one URL (domain1.com) sent to a specific index.htm located in folder "A", while users coming to the same ip address using the other URL (domain2.com), being sent to a different index.htm file in folder "B" using mod_rewrite and/or htaccess, without using a virtual server configuration?

Thanks in advance
YoDude9999
 
Posts: 11
Joined: Wed Nov 22, 2006 2:19 am

Postby richardk » Tue Jul 22, 2008 9:53 am

Both the domains go to the same document root?

Try the following in a .htaccess file in the document root
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Add missing trailing slashes.
RewriteCond %{HTTP_HOST}/one ^(www\.)?example-one\.com(/one)$ [NC,OR]
RewriteCond %{HTTP_HOST}/two ^(www\.)?example-two\.com(/two)$ [NC]
RewriteCond %{DOCUMENT_ROOT}%2%{REQUEST_URI}/ -d
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]

RewriteCond %{ENV:REDIRECT_STATUS}
RewriteCond %{HTTP_HOST}/one ^(www\.)?example-one\.com(/one)$ [NC,OR]
RewriteCond %{HTTP_HOST}/two ^(www\.)?example-two\.com(/two)$ [NC]
RewriteRule ^(.*)$ %2/$1 [QSA,L]

You must change all "example-one\.com", "example-two\.com", "/one" and "/two" to the domains and sub directories.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby YoDude9999 » Wed Jul 23, 2008 12:36 am

Yes, both domains point to the same index.htm file in the document root.

I see I had forgotten to mention that there is an index.htm file for domain1.com and index.php for domain2.com. I'll see if I can work this out with what you have provided.

I'll be back to let you know how it goes, thanks again :)

On edit:

I was getting internal server errors with this line of code:

Code: Select all
RewriteCond %{ENV:REDIRECT_STATUS}


but fixed it with:

Code: Select all
RewriteCond %{ENV:REDIRECT_STATUS} ^$


It seems I should have been a little more clear with what I am trying to do.

Perhaps an example of the site structure would help.

Where folder "Web Site" is the document root for domain1.com (entering the domain2.com URL will currently take users to the domain1.com index.htm page).

C:\web site\index.htm

and domain2.com needs to point to something like this:

C:\Web Site\folder1\folder2\folder3\index.php

I realize it's pretty screwy the way I've done this, but to change the structure from what it is now, would be a major undertaking requiring a lot of CGI script editing and re installation of the forum code that resides at the index.php location of domain2.com

I suppose all that really needs to happen here is for users to be redirected to the proper index.php file at the proper location of the site when using the domain2.com URL and everything else already is functional.

The code you have provided thus far however does in fact work after fixing that one line, but doesn't need to really do anything with the domain1.com URL and just really needs to get users to the correct location and bring up the index.php file when addressing the domain2.com URL

I'm so sorry for all the confusion
YoDude9999
 
Posts: 11
Joined: Wed Nov 22, 2006 2:19 am

Postby richardk » Wed Jul 23, 2008 7:23 am

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Add missing trailing slashes.
RewriteCond %{HTTP_HOST} ^(www\.)?example-two\.com$ [NC]
RewriteCond %{DOCUMENT_ROOT}/path/to/example-two%{REQUEST_URI}/ -d
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]

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

Postby YoDude9999 » Thu Jul 24, 2008 3:35 am

Richard,

This works with but one exception. When going to the example-two.com URL,
instead of the index.php file being loaded, a list of files in the directory is shown instead. I assume this is because browsers are defaulting to htm.
YoDude9999
 
Posts: 11
Joined: Wed Nov 22, 2006 2:19 am

Postby richardk » Thu Jul 24, 2008 1:33 pm

It is the servers decision to decide what file to show. With Apache you can change it with the DirectoryIndex directive. Add
Code: Select all
DirectoryIndex index.html index.htm index.php
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby YoDude9999 » Thu Jul 24, 2008 7:59 pm

Thank you so much Richard, again you're a Hero. Everything is working perfectly. :D
YoDude9999
 
Posts: 11
Joined: Wed Nov 22, 2006 2:19 am


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 1 guest

cron