954,587 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How do you use the same files with two domains, through .htaccess?

Sorry if this is in the wrong section (PHP), but wasn't sure where to put htaccess issues....

Here's the deal - I have two domains, let's say domain1.com and domain2.com. On my web server, I have domain1 set up as the primary domain (/public_html/), and domain2 is an addon domain (/public_html/domain2.com/).

What I'd like to accomplish through .htaccess is to access my files from domain1 through domain2, which is shorter - so for example, if under domain1 I have a /admin/ folder (accessed through domain1.com/admin/), I'd like to also be able to access it through domain2.com/admin/. Would this be possible (without redirecting one entire site to the other, since they serve different purposes) through .htaccess?

bthaxor
Newbie Poster
12 posts since Dec 2008
Reputation Points: 10
Solved Threads: 0
 

Well, I have no idea how to do that with HTACCESS, but maybe you could post the server you use ... maybe someone knows of a tool that'll let you do that.

kooia
Light Poster
35 posts since Apr 2010
Reputation Points: 11
Solved Threads: 4
 

I'm under shared hosting (Apache environment), so htaccess would probably be my best bet...

bthaxor
Newbie Poster
12 posts since Dec 2008
Reputation Points: 10
Solved Threads: 0
 

By accessing your files, do you mean in (php) code ? If so, if you use absolute paths the files should all be accessible to you.

pritaeas
Posting Expert
Moderator
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 
By accessing your files, do you mean in (php) code ? If so, if you use absolute paths the files should all be accessible to you.

I mean that I would be able to access http://domain1.com/somefile.txt through http://domain2.com/somefile.txt also...

bthaxor
Newbie Poster
12 posts since Dec 2008
Reputation Points: 10
Solved Threads: 0
 

Something like this:

RewriteCond %{http_host} ^domain2.com [nc]
RewriteRule ^(.*)$ http://www.domain1.com/$1


If you want this for just specific files, just replace the .*

pritaeas
Posting Expert
Moderator
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

Something like this:

RewriteCond %{http_host} ^domain2.com [nc]
RewriteRule ^(.*)$ http://www.domain1.com/$1

If you want this for just specific files, just replace the .*

Thanks for that, but I already knew about a full-domain redirect - I mentioned in the OP that: I'd like to also be able to access it through domain2.com/admin/. Would this be possible (without redirecting one entire site to the other, since they serve different purposes)

This is the real problem here =\

Thanks for the attempt though...

bthaxor
Newbie Poster
12 posts since Dec 2008
Reputation Points: 10
Solved Threads: 0
 

You can add the admin part in the RewriteRule

RewriteRule ^admin/(.*)$ http://www.domain1.com/admin/$1

Change the .* to the filename you want to access, since you don't want all to be redirected.

pritaeas
Posting Expert
Moderator
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

So I would have to do this for every single file in both domains?

Not exactly what I was looking for, but I guess for one or two files I could employ this...

Perhaps I'm to blame though, I don't think I made myself clear enough - I would like to be able, for both domains, to be able to access ANY file or folder (e.g. http://domain1.com/file.txt or http://domain1.com/folder/ ) through the other domain ( http://domain2.com/file.txt or http://domain2.com/folder/ ), AND VICE VERSA, so the two domains are 'interworking' to access the same files through their respective URLs. I know it's quite a big ask but... Just wanted to know if I could do anything like this.

bthaxor
Newbie Poster
12 posts since Dec 2008
Reputation Points: 10
Solved Threads: 0
 

Hmz, don't think that is possible throught htaccess, because that could cause infinite redirect loops. Sounds more like you want a load-balancer, but that would make only sense between two different servers.

pritaeas
Posting Expert
Moderator
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: