Home > Mobile >  Redirecting to new domain page without changing the old domain name
Redirecting to new domain page without changing the old domain name

Time:06-03

I have two different domains olddomain.com and newdomain.com .All working pages are in olddomain only. Only one page in new domain So,when they click on newdomain/subpageurl content should display from newdomain/subpage but url should be olddomain.com/subpage

newdomain.com/subpage1 -->olddomain.com/subpage1

But URL should be like olddomain.com/subpage1

I tried this..

RewriteEngine On
RewriteCond %{HTTP_HOST} olddomain.com$
RewriteRule (.*) http://newdomain.com/$1 [R=301,L]

CodePudding user response:

First, You have to put your new domain page file into the old domain. make a sub folder in your old domain root folder. then upload your file into the sub folder. Like olddomain.com/subfolder/files

CodePudding user response:

You are probably looking for a way to implement a transparent proxy inside olddomain forwarding requests to newdomain. As said in the comments to the question you are vague in that.

Two immediate alternatives exist. Both approaches require the proxy module to be loaded into the http server on olddomain.com, obviously. More precisely the proxy and the proxy_http module. I assume here that you are using the apache http server to serve olddomain.com ...


Using the rewrite module, which is able to use the internal proxy module:

RewriteEngine on
RewriteRule ^/?subpage/?$ https://newdomain.com/subpage [P]

The documentation: https://httpd.apache.org/docs/current/rewrite/flags.html#flag_p


Directly using the proxy module:

ProxyRequests off
ProxyPass /subpage https://newdomain.com/subpage
ProxyPassReverse  /subpage https://newdomain.com/subpage

Documentation: https://httpd.apache.org/docs/2.4/mod/mod_proxy.html#proxypass

And yes, it is ProxyRequests off and not ProxyRequests on.


Both approaches work for requests targeting olddomain.com (https://olddomain.com/subpage). This will not work for requests directly targeting newdomain.com. For that you would have to implement an additional external redirection in newdomain.com pointing to olddomain.com. That is a bit tricky however since you have to take care to not redirect those requests that came through the proxy on oldcomain.com. Because that would lead to a redirection loop.

  • Related