Redirecting ip to domain name

1k views Asked by At

I am working on a small project, I changed http://localhost to http://myowndomain.com and it's working good. I was curious and gave domain name to facebook.com . But it will redirect to original Facebook website.

I got an idea, and used apache rule

RewriteEngine On

RewriteBase /

RewriteCond %{HTTP_HOST} ^12\.34\.56\.789$
RewriteRule ^(.*)$ http://www.domainname.com/$1 [L,R=301]

Here, in the place of domainname if I use Facebook it will again redirect to original site.

Is there any way to so that I can bind my offline Facebook page (index.html) with my static ip address and I someone enters my ip, they get facebook.com in the domain name.

1

There are 1 answers

0
Inc0 On

Sppofing dns replies is an overkill and modified hosts files on every pc is tedious. Not knowing your network doesn't help either but if I were you, to achieve what you want, I would use bind and rpz (https://www.zytrax.com/books/dns/) or dnsmaquerade (easier solution).

About your original problem, what you should do is:

  • make sure myowndomain.com resolves to the ip of the server where pages are located (resoluton is done by the DNS server the client is using)
  • if you need a rewrite rule to redirect traffic, first you need 2 virtual hosts: one handling request for the domain you want to use and a default one catching every other requests. The default one is the only one where you should put a rewrite rule to redirect everything to your main website. The rule you need in the default vhost is something like this:
RewriteEngine On
RewriteCond (.*) http://domainname.com$1 [L,R=301]

Please remember "domainname.com" and "www.domainname.com" are different domains: both need to be resolved with an ip address (which can be the same) so if you want to use both domains, the virtualhost you have to setup must be configured to handle requests for for domains and it should look like this:

ServerName domainname.com
ServerAlias www.domainname.com
#ServerAlias *.domainname.com