Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

switching between ssl and non-ssl using relative links

Status
Not open for further replies.

awingnut

Programmer
Feb 24, 2003
759
US
Is there a way to specify an href, using relative links, from a non-secure page to a secure page and vice-versa? TIA.
 
I've not tried this, but it might work:

From https to http:
Code:
<a href="[URL unfurl="true"]http://./somepage.html">link</a>[/URL]

From http to https:
Code:
<a href="[URL unfurl="true"]https://./somepage.html">link</a>[/URL]

Dan

[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]
 
Hmm.. you might try it without the initial "./" - it might work, too.

Dan

[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
Thanks but I take it from your replies that this is has not been addressed before which I find odd (I'm never the first to think of anything). However, it seems that neither works.
 
I don't think there's any way to do it.

Returning to first principles, a URL consists of a series of parts, from left to right (these might not be the official names for them):
[ol]
[li]Scheme: " (or " "ftp://" etc.)[/li]
[li]Server: "www.tektips.com"[/li]
[li]Port (optional): ":80"[/li]
[li]Path: "/"[/li]
[li]Page: "viewthread.cfm"[/li]
[li]Query: "?qid=1080777&nx=1"[/li]
[li]Fragment: "#newpost"[/li]
[/ol]
You can write an absolute URL by entering all these values (well, all the ones that apply anyway).

If you make a relative URL by only writing some of the values, values further down the list (right) of those you specify will be set to nothing, those further up (left) of your values will be set equal to the current page. So if you put a link to "mypage.htm", it inherits the scheme, server, port and path from the current page and sets the query and fragment to nothing.

So, returning to the original question: there's no way to write a relative URL from an https: to a http: address, because if you specify a new scheme, you have to specify everything else.

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
You can do it with JavaScript, it seems. I'm not sure that this solution is all that practical for anything other than a known target audience (intranet, etc), but it might be a solution that is good for you.

Code:
<html>
<head>
	<script type="text/javascript">
	<!--
		function setupLinks() {
			var anchors = document.getElementsByTagName('a');
			for (var loop=0; loop<anchors.length; loop++) {
				if ((' ' + anchors[loop].className + ' ').indexOf(' http ') != -1) anchors[loop].protocol = 'http:';
				else if ((' ' + anchors[loop].className + ' ').indexOf(' https ') != -1) anchors[loop].protocol = 'https:';
			}
		}
	//-->
	</script>
</head>
<body onload="setupLinks();">
	<a href="page1.html" class="http">Unsecure Link</a>
	<a href="page1.html" class="https">Secure Link</a>
</body>
</html>

Dan

[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top