June
June

Reputation: 25

Redirect domain to a directory while retaining address

I have two domains (example.com and example2.com) that direct to the same location. I want to redirect one of the domains (example2.com) to a directory (example.com/dir), without any of the following occurring:

So that:

Thanks in advance

Upvotes: 2

Views: 50

Answers (1)

Panama Jack
Panama Jack

Reputation: 24448

So given that both domains point to the same document root, then you should be able to use this rule to rewrite example2.com to /dir.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?example2\.com [NC]
RewriteRule ^(.*)$ /dir/$1 [L]

If that is not the case and they are not on the same servers, you will have to use mod-proxy [P] to accomplish this task. This would go on the example2.com .htaccess.

RewriteEngine On
RewriteRule ^(.*)$ http://example.com/dir/$1 [P]

Upvotes: 1

Related Questions