Log in

View Full Version : Show IP instead of URL?



BLiZZaRD
08-23-2006, 11:36 AM
Just wondering how you can do this? I know URLs and IPs are linked and coherant, but if my IP for my site is 111.222.333.444 and my URL is mysite.com what do I need to do to make the URL resolve to 111.222.333.444 instead of mysite.com?

I was thinking htaccess Mod_ReWrite, but I couldn't find anything??

Ideas?

And before you ask, it is just a novelty thing and will be done on only one part of my site (albeit the entire site at this point, LOL)

Thanks.

BLiZZ

Twey
08-23-2006, 01:27 PM
I know URLs and IPs are linked and coherantNot necessarily so, for a shared host.

You can't have an IP section above 255 for a start :p
I think you mean that you want to redirect from the domain to the IP, yes? This will be impossible on a shared host.

According to HTTP/1.1, the user agent must include a "Host" HTTP header with each request. The header looks like this:
Host: www.mysite.comThis allows multiple domains to be served from the same server -- shared hosting. If you access a site by its IP, the IP will be used in the Host header instead of the domain name. If the server uses shared hosting, it will get confused about which site to deliver.

BLiZZaRD
08-24-2006, 08:01 AM
Ahh, thanks for that Twey. I know it is possible, as I see sites all the time that have the IP in the url instead of the words. Just curious as to how they pulled it off.

Thanks.

Twey
08-24-2006, 11:12 AM
If it's a dedicated host (it serves the same site no matter what Host header it's given) there's no problem with doing this.

BLiZZaRD
08-25-2006, 08:35 AM
That makes perfect sense. But the question still remains.. HOW?

codeexploiter
08-25-2006, 10:22 AM
A site which is accessible through an IP Address rather than a Domain name is fully depends upon the Domain Name System (DNS).

For example, if a party doesn't have a domain, then the only way to access their server is through their public IP Address. There are people who hosts their web sites through a Cable Modem without having a domain name like http://www.dynamicdrive.com. In order to access such web sites they have to enter their server's IP Address directly.

If they are possessing a dynamic IP then they can setup a dynamic DNS. Dynamic DNS is a system which allows the domain name data held in a name server to be updated in real time. The most common use for this is in allowing an Internet domain name to be assigned to a computer with a varying (dynamic) IP address. This makes it possible for other sites on the Internet to establish connections to the machine without needing to track the IP address themselves

Even if they have a valid domain name the site might be only available through their IP Address, the main reason for this is if they never made a DNS entry for that server.

If you check out your DNS server, it is basically a list of names, and the IP address of the server that has that name. If you put a server on the Internet with a valid IP address, but you dont make an entry in DNS for it, then you will only be able to access it by the IP address.

If you want you can visit a site (I don't know whether this site is popular or not :D) http://64.233.167.104/

Twey
08-25-2006, 03:31 PM
That makes perfect sense. But the question still remains.. HOW?If it's a dedicated host, one can simply enter the IP of the site instead of its domain name.

http://216.118.83.123/

BLiZZaRD
08-26-2006, 02:10 PM
If it's a dedicated host, one can simply enter the IP of the site instead of its domain name.

http://216.118.83.123/


Right I know that... but entering the dotted quad is not easy for most people.

What I was looking for originally was like an htaccess line or Mod ReWrite to change that.

For example, you can add or eliminate the WWW in the url whether the visitor uses it or not using Mod ReWrite lines.

What I was looking for is similar in forcing the dotted quad to show even if the visitor entered the name URL.

blm126
08-26-2006, 02:43 PM
Set your domain name up to redirect to the IP instead of using a name server

mwinter
08-26-2006, 03:49 PM
Right I know that... but entering the dotted quad is not easy for most people.

Which was precisely why host names and the DNS system was introduced. :)



What I was looking for originally was like an htaccess line or Mod ReWrite to change that.

The mod_rewrite Apache module can do this and the examples in the Apache documentation should make it clear how do write the appropriate directives (see Canonical Hostnames (http://httpd.apache.org/docs/2.2/rewrite/rewrite_guide.html#canonicalhost)). However, these rules cannot be used within a .htaccess file, only the server configuration (mod_rewrite works differently at the directory level).

As Twey noted, this will only work for dedicated hosts, or those that use IP-based virtual hosting. Doing this with a server dependent upon name-based virtual hosts will make the server useless.

Mike

Twey
08-26-2006, 04:45 PM
As Twey noted, this will only work for dedicated hosts, or those that use IP-based virtual hosting. Doing this with a server dependent upon name-based virtual hosts will make the server useless.Luckily, his is one of those.
What I was looking for is similar in forcing the dotted quad to show even if the visitor entered the name URL.The easiest way, if .htaccess is limited here, is to include a simple line at the top of the pages:
<?php if(strpos($_SERVER['HTTP_HOST'], 'cleverwasteoftime') !== false) header('Location: http://216.118.83.123' . $_SERVER['REQUEST_URI']); ?>

BLiZZaRD
08-27-2006, 08:55 AM
Which was precisely why host names and the DNS system was introduced. :)


:D Yeah.. someone got smart way back when, LOL I would have started at 1, then each site would have a number corresponding to date and order URL was made. But I have a pinache for the over-exuberant (is that even a word?)



The mod_rewrite Apache module can do this and the examples in the Apache documentation should make it clear how do write the appropriate directives...

Thanks.. I did look on Apache's site in the Mod Rewrite section.. but I got lost and nothing looked like what I wanted.

[hr]

Luckily, his is one of those.

must be IP based, as my non-profit sites can't afford dedicated yet :)



The easiest way, if .htaccess is limited here, is to include a simple line at the top of the pages:
<?php if(strpos($_SERVER['HTTP_HOST'], 'cleverwasteoftime') !== false) header('Location: http://216.118.83.123' . $_SERVER['REQUEST_URI']); ?>


Cool! I will give all these a try. Thanks guys :D