简体   繁体   中英

.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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM