Holly
Holly

Reputation: 7752

.htaccess rewrite to redirect & change url in address bar

I'm trying to direct domanin2.com the page at domain1.com/landing-page/ but I would like the browser to display domanin2.com in the url address bar. Is there a way to do this?

So far I've tried this in my .htaccess file:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^domanin2\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.domanin2\.com$
RewriteRule ^/?$ "http\:\/\/domain1\.com\/landing-page\/" [R=301,L]
RewriteRule ^\.html$ /domanin2/ [L]

It works in so far as domanin2.com is redirected to domain1.com/landing-page/ but domain1.com/landing-page/ is also displaying in the url address bar rather than domanin2.com.

Is this posible, I'm trying to avoid getting a second hosting account. I own both domains.

Upvotes: 0

Views: 1562

Answers (1)

Jon Lin
Jon Lin

Reputation: 143856

If both of your domains are on different servers or have different document roots, the only thing you can do is use mod_proxy. Most hosting services turn this off as they don't want people proxying, but if you have it turned on, replace the R=301 with a P.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^domanin2\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.domanin2\.com$
RewriteRule ^/?$ "http\:\/\/domain1\.com\/landing-page\/" [P,L]
RewriteRule ^\.html$ /domanin2/ [L]

But it won't work at all if apache doesn't have mod_proxy loaded.

Upvotes: 3

Related Questions