Trey
Trey

Reputation: 5520

.htaccess rewrite from subdirectory of domain to subdirectory of different domain

Ok, I've found a few threads pertaining to very similar issues, but haven't had any luck using the answers provided for my own site. Basically I have 2 sites, mapped like this:

/public_html/ - points to main domain (www.site1.com)
/public_html/site2.com - points to secondary domain (www.site2.com)
/public_html/portal - points to my target subdirectory

I'm trying to get all requests to www.site2.com/portal to load www.site1.com/portal transparently, that is I still want www.site2.com/portal to show in the address bar.

RewriteCond %{HTTP_HOST} ^(www\.)?site2\.com [NC]
RewriteCond %{REQUEST_URI} ^/portal/(.*)$
RewriteRule ^/(.*) /portal/$1 [L]

doesn't work at all

RewriteCond %{HTTP_HOST} ^(www\.)?site2\.com$ [NC]
RewriteCond %{REQUEST_URI} ^/portal/(.*)$
RewriteRule ^(.*)$ http://site1.com/portal/$1 [L]

takes me to http://site1.com/portal/site2.com/portal.

I've been beating my head against a wall over this for a couple days, any help would be appreciated!

Upvotes: 1

Views: 850

Answers (1)

anubhava
anubhava

Reputation: 785481

Your current setup is not going to support what you are trying to get unless you enable mod_proxy in your httpd.conf. So here are 2 options available with you:

Option 1: Enable mod_proxy and retain current directory structure

Put this code in your .htaccess under public_html/site2.com directory:

RewriteCond %{HTTP_HOST} ^(www\.)?site2\.com$ [NC]
RewriteRule ^(portal/.*)$ http://site1.com/$1 [L,NC,P]

Option 2: Retain current directory structure and create a symbolic link like this:

/path-to/public_html/site2.com/portal -> /path-to/public_html/portal

Then put this code in your .htaccess under public_html/site2.com directory:

Options +FollowSymLinks -MultiViews

IMHO option # 2 is going to be much easier for you since it just requires creating one symbolic link (I believe you are using some flavor of *nix.

Upvotes: 1

Related Questions