Solved

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

Posted on 2003-11-12
13
2,375 Views
Last Modified: 2010-04-09

How to do that?
http:// address redirect to http://www address
0
Comment
Question by:gizmoadria
  • 4
  • 2
  • 2
  • +5
13 Comments
 
LVL 1

Expert Comment

by:ric7ho
ID: 9732981
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
 

Author Comment

by:gizmoadria
ID: 9733057
does the script go in the header?
body?

what happens if my pages are php based?
0
 

Author Comment

by:gizmoadria
ID: 9733061
Any other ways?
0
 
LVL 2

Expert Comment

by:Yavor_01126
ID: 9733150
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
 
LVL 8

Expert Comment

by:MusicMan
ID: 9733152
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
 

Author Comment

by:gizmoadria
ID: 9733307

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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 1

Expert Comment

by:dstark
ID: 9736454
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
 
LVL 16

Expert Comment

by:jaysolomon
ID: 9737179
i would use location.replace

if(location.href == "http://site.com"){
     location.replace("http://www.site.com");
}
0
 
LVL 2

Accepted Solution

by:
mailBoy2 earned 50 total points
ID: 9738100
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
 

Author Comment

by:gizmoadria
ID: 9740325
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
 
LVL 2

Expert Comment

by:Yavor_01126
ID: 9743391
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
 
LVL 1

Expert Comment

by:ric7ho
ID: 9747770
>>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
 
LVL 7

Expert Comment

by:TheKenman
ID: 10219611
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

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now