473,414 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Redirect to server root address

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.

Nov 28 '05 #1
5 8730
sc*****@gmail.com 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.
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 28 '05 #2
Thanks for that. But I want to clarify something, will
http://javascript:this.domain:8080/index.html" work.

cheers.

Nov 28 '05 #3
sc*****@gmail.com 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.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 28 '05 #4
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.

Nov 28 '05 #5
sc*****@gmail.com wrote:
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
Nov 29 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Sean Berry | last post by:
Hi there. I am relativly new to Python CGI and need a question answered. I have made custom 404 error pages and have them in various web directories. I have not been able to figure out a way...
3
by: Paul | last post by:
I'm not getting the results I want when I use Response.Redirct in a ASP page. I enter this line of code in a asp page from domain1.com. Response.Redirect...
2
by: Robert Gordon | last post by:
I now realize I probably should have tried posting this on the IIS board first.. I am running OWA 2003 Server as Front End server to my Exchange 2000 native domain. The FE server is secured by...
3
by: Hans | last post by:
Hi there, I have a number of domain names and they all point to the same IP address. I would like to redirect to a specific folder, based on the domain name used to access the site. For example....
11
by: Stephen | last post by:
I was wondering if someone can help me with an web application design problem. I have a aspx page which builds up an arraylist called addresses and outputs the values in the arraylist items to a...
0
by: WebHouse.Co | last post by:
Hi Sir I'm in my 2nd year in M.Sc. degree & I made a project about the powerful tools SQLXML 3.0 & updategram, so I made a list of programs which r they so similar to the example that using...
3
by: MBW | last post by:
The following code is for a simple server/client asplication that allows the user to toggle between serve and or client modes and send/recieve a message however i am getting an Attribute error on...
3
by: Calvin KD | last post by:
Hi everyone, I don't know if there's anyone out there is having the same problem. My DotNet 1.1 version uses FormsAuthentication.RedirectFromLoginPage() method to take user from the Login page to...
3
by: Alan Silver | last post by:
Hello, Sorry if this is a stupid question, but I can't really see much difference between these tow methods according to the scant info in the SDK. Could anyone enlighten me? TIA -- Alan...
10
by: Eirik Eldorsen | last post by:
How can I 301 redirect www.example.com/default.aspx to www.example.com without using ISAPI filters?
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.