Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Development Tools

Redirecting a domain to a subdirectory of another website with htaccess

When a visitor enters www.example1.com, I'd like to show the contents of www.example2.com/subdir. However, I want the user to still see "www.example1.com" as the URL. I own both domains and have access to htaccess, but I can't seem to figure out how to make this happen without resorting to cloaking.

Here's what I've tried in my .htaccess file thus far:

RewriteEngine On
RewriteCond %{HTTP_HOST} www.example1.com
RewriteRule ^(.*)$ http://www.example2.com/subdir/ [R=301,L]

I've also tried giving www.example1.com an A record of www.example2.com's server IP, to no avail.

Any suggestions would be greatly appreciated! Thanks!

Can you create an HTML file on www.example1.com and use an

<iframe>

inside the HTML file to point to www.example2.com/subdir? Would that be considered cloaking?