Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
180 views
in Technique[技术] by (71.8m points)

linux - Redirecting ip to domain name

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.

question from:https://stackoverflow.com/questions/65873321/redirecting-ip-to-domain-name

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...