I have to redirect content on a webserver with a hostname (mydomain.com
) from current IP (123.123.123.123
) to a new IP (234.234.234.234
), while keeping the same hostname, using .htaccess
. How can I do that?
I have to redirect content on a webserver with a hostname (mydomain.com
) from current IP (123.123.123.123
) to a new IP (234.234.234.234
), while keeping the same hostname, using .htaccess
. How can I do that?
If you can use
RewriteRule
in your.htaccess
file, you can't "redirect" per se, but you can reverse-proxy the connections to 123.123.123.123 out to 234.234.234.234, so that you only have to maintain the single website.This assumes that host 123.123.123.123 can connect to host 234.234.234.234 directly. Connections from users who are getting "123.123.123.123" as the IP for your DNS name will go to the old server, but then Apache will make a request on their behalf to the new server and return the results of that request back to the user.
An important side effect of this is that the client IP will get lost in the shuffle, as host 234.234.234.234 will see the requests as all coming from host 123.123.123.123. However, Apache does set an
X-Forwarded-For
header which you can log if you choose.WARNING: The one possible snag in this setup is that the connections coming into 234.234.234.234 will send a
Host
header of "234.234.234.234" which may be okay if your site is the only one on that IP, but if your new hosting location is using named virtual hosts, it will likely fail.In that case, the best option would be to use a different DNS host. You should be able to set the authoritative name servers on your DNS record to point to somewhere else, either your new web hosting provider might provide this service, or for maximum control you can take over control of your records yourself using a service such as Amazon Route 53.
The problem is not about your rewriterule, it's about your DNS configuration.
My own DNS configuration is something like:
This means "if you type
papdevis.fr
or whatever behind i.e.www.papdevis.fr
orolivier.papdevis.fr
go to the server at the adress123.123.123.123
.If I change the adress
123.123.123.123
to a new one for example234.234.234.234
, this will work and as soon as you'll typepapdevis.fr
or any other stuff (like explained before) it will go to234.234.234.234
. Everything will work smoothlessly without touching any.htaccess
file.