HowTo: http:// address redirect to http://www address -I see many sites where http:// won't load


How to do that?
http:// address redirect to http://www address
gizmoadriaAsked:
Who is Participating?
 
mailBoy2Commented:
If you own both www.site.com and site.com you can just set your webserver to redirect from site.com to www.site.com. That way you don't need to have anything in the actual pages and the web server catches it so there is very little processing. Also a <meta http-equiv="refresh" content="0; url=http://www.site2.com"> line in your code means that the user has to first download this file then download a second file - over a 56K modem it can be a bit anoying as it just takes a little extra time.
0
 
ric7hoCommented:
for example- if you want http://yahoo.com to be redirected to http://www.yahoo.com. add the following code:

<script>
 if(top.location == "http://yahoo.com"){
   top.location = "http://www.yahoo.com";
 }
</script>
0
 
gizmoadriaAuthor Commented:
does the script go in the header?
body?

what happens if my pages are php based?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
gizmoadriaAuthor Commented:
Any other ways?
0
 
Yavor_01126Commented:
hmmm
basicly that is problem for the browser which are not well programed but this method should work well and it is typed in the <head> ...
but I sugest that you simply add more info in the header for the page ... I mean description !
That should ease some browsers some not but if you desire the best way of redirecting it is simply to go trough the HTTP protocol because I think that isn't work of the designer of a web page .

And about PHP , there is no problem just stay cool !

Regards !
0
 
MusicManCommented:
If you are trying to redirect users from one site straight to another try using this as the index.html file of site 1

<html>
<head>
<meta http-equiv="refresh" content="0; url=http://www.site2.com">
</head>
</html>

Is that what you mean?
0
 
gizmoadriaAuthor Commented:

I have noticed more and more, some sites come up if you type in just:

site.com

others will give errors so  you have to type in

http://www.site.com
www.site.com

I want attempts to load "site.com" from the browser actually load up, rather than "Page Not Found"

0
 
dstarkCommented:
That's because techincally site.com and www.site.com are two different websites..

Depending on how the webserver is setup, will determine what is sent back to the client..

You mentioned PHP above.. Im assuming that you are using Apache on a *nix box?  You need to make sure that your httpd.conf is setup to handle both site.com and www.site.com .. Multiple ways of accomplishing this..
0
 
jaysolomonCommented:
i would use location.replace

if(location.href == "http://site.com"){
     location.replace("http://www.site.com");
}
0
 
gizmoadriaAuthor Commented:
dstark

technically, they are 2 different sites?

Mailboy2, my point exactly, I don't want to have user download page first to then be redirected.
0
 
Yavor_01126Commented:
I don't really know how the http run these things but what I'm sure about is that it is in the protocol ... I mean that www is just some description like news or mil (military) and such other descriptions for type of sites ... but what the problem is ?!? It is in the http protocol !

you have       http://site.com
and              http://www.site.com

try making some logical understand to this !

I read a book (100 pages) about http and the experience that the book actualy gave me was basicly but at least I have an understanding with the protocol and what in the book is all writen about is just that http is not so coded(maybe not a good word) in a page than in server or app .
Try the script the people gave you in top if not try to configure you apache or what ever server you are administrating if you aren't the admin of the server and the server is commercial waybe the admins of it can tell you more about your problem but as I said try to read about http protocol to understand what it is all about and how it works ...


Regards !
0
 
ric7hoCommented:
>>does the script go in the header?
>>body?

>>what happens if my pages are php based?

It can go to anywhere in the page in theory. but in the header would probably be the best...

It does not matter if the pages are php based
0
 
TheKenmanCommented:
Even though this is old, I'd just like to add (for reference) that the difference in the 2 sites is the DNS.

site.com = 1 DNS record
www.site.com = another DNS record

ww.site.com, w.site.com, ftp.site.com, lots.of.sub.domains.like.microsoft.com...

Each of those are a different DNS record, each residing on a zone file for site.com. Within each record, you can set the address of the site to an IP or to another address on that zone ( I believe it has to be that same zone anyways...)

So if you can't get to a site by typing in www., that means the webmaster and/or the DNS admin is lazy...


<|ken|Wed Jan 28 10:35:26|>nslookup www.w3schools.com

Non-authoritative answer:
Name:   www.w3schools.com
Address: 148.122.2.11

<|ken|Wed Jan 28 10:35:30|>nslookup w3schools.com

Non-authoritative answer:
*** Can't find w3schools.com: No answer

Yet...

<|ken|Wed Jan 28 10:37:37|>nslookup www.experts-exchange.com

Non-authoritative answer:
www.experts-exchange.com        canonical name = experts-exchange.com.
Name:   experts-exchange.com
Address: 64.156.132.140

<|ken|Wed Jan 28 10:37:47|>nslookup experts-exchange.com

Non-authoritative answer:
Name:   experts-exchange.com
Address: 64.156.132.140
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.