Redirect to server root address

S

sconeek

hi all,

I am trying to re-direct a html page to the root of a server (eg.
localhost:8080/index.html). However the problem is that I dont want to
hard code the name of the server (localhost) as it will change
periodically. I want to reference just the server name (whatever it is)
and then the port no and then the file name. I hope we can achieve this
using Javascript.

So far I have written:
<META HTTP-EQUIV="REFRESH" CONTENT="3;
URL=http://localhost:8080/index.html">

can some genius help me with this.

thanks in advance.
 
R

Randy Webb

(e-mail address removed) said the following on 11/28/2005 1:38 AM:
hi all,

I am trying to re-direct a html page to the root of a server (eg.
localhost:8080/index.html). However the problem is that I dont want to
hard code the name of the server (localhost) as it will change
periodically. I want to reference just the server name (whatever it is)
and then the port no and then the file name. I hope we can achieve this
using Javascript.

So far I have written:
<META HTTP-EQUIV="REFRESH" CONTENT="3;
URL=http://localhost:8080/index.html">

can some genius help me with this.

thanks in advance.

var thisURL = document.location.href;
var thisDomain = document.domain;

Now, you have the URL itself, you can pick out the host, add the port,
and your file name.
You also have a reference, where supported, to the domain itself as well.
 
R

Randy Webb

(e-mail address removed) said the following on 11/28/2005 1:58 AM:

Please quote what you are replying to.

If you want to post a followup via groups.google.com, don't use the
"Reply" link at the bottom of the article. Click on "show options" at
the top of the article, then click on the "Reply" at the bottom of the
article headers.
Thanks for that. But I want to clarify something, will
http://javascript:this.domain:8080/index.html" work.

It is easy enough to test but the answer is no.

You will have to build your own URL and then use JS to simply set the
document.location.href to the appropriate URL.

document.domain seems to be a property that can be set but not read.
Bummer.

Get the location.href property, then weed out the part you need. It will
be everything from the beginning up to the first '/' that is not part of
the '//'. Then, build your own URL string, set the location.href to that
string, then you are set.

Search the archives. You can probably find something already written
that will give you the current domain.
 
S

sconeek

I found something else within the archives. I need to do exactly this,
but am not sure how to implement it with a javascript method. could
somebody please guide me.

If this is the case, I would use Regular Expressions to return the
first match of:
/[ps]:\/\/([^\/]*\.)$\/?

Not sure on the \/... you might also try:
/[ps]://([^/]*\.)$/?

This should return the following for the following strings:
http://123.123.123.123/here.htm Returns:123.123.123.123
https://mydomain.com/here.htm Returns:mydomain.com
http://this.is.my.domain.name Returns: this.is.my.domain.name

thanks heaps.
 
T

Thomas 'PointedEars' Lahn

I found something else within the archives. I need to do exactly this,
but am not sure how to implement it with a javascript method. could
somebody please guide me.

If this is the case, I would use Regular Expressions to return the
first match of:
/[ps]:\/\/([^\/]*\.)$\/?

Not sure on the \/... you might also try:
/[ps]://([^/]*\.)$/?

Both would match `p://.'
This should return the following for the following strings:
http://123.123.123.123/here.htm Returns:123.123.123.123
https://mydomain.com/here.htm Returns:mydomain.com
http://this.is.my.domain.name Returns: this.is.my.domain.name

RFC3986, Appendix B, includes a Regular Expression for parsing URIs
that you could use.

However, you better configure your server accordingly so that it
responds with a 3xx status code, probably 301 or 302, and a
Location header that indicates the new location. Works everywhere
while your approach requires client-side script support. See also
<URL:http://www.w3.org/QA/Tips/reback>.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top