-->

Stealth Domain forwarding

2019-06-02 10:24发布

问题:

what is the easiest way to stealth forward this first.domain.com to second.domain.com? Been trying it with this codes in .htaccess:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^first.domain.com$
RewriteRule (.*)$ http://second.domain.com [R=301,L]

and

rewriteengine on
rewritecond %{REQUEST_URI} first.domain.com/
rewriterule (.*) http://second.domain.com [l,nc]

But I'm having no luck at all. I want to retain "first.domain.com" on my address bar even when the page is already on second.domain.com. Thanks in advance.

回答1:

You want the first, but notably you need to replace R=301 with P (for proxy), and you can add a backreference for the rule match:

RewriteRule ^(.*)$ http://second.domain.com/$1 [P,L]

This way, http://first.domain.com/some/file.html will get proxied to http://second.domain.com/some/file.html and the address bar will still say: http://first.domain.com/some/file.html