[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


How do I specify the href= from HTTP to HTTPS using relative paths instead of qualified paths?

Posted on 2009-02-19
Medium Priority
Last Modified: 2012-08-13
Our website uses relative paths to access various folders to display the html content:
<a href="../home/index.html>
<a href="../travel/index.html>

For obvious reasons, I want to keep the paths in the href tag relative since we tend to move around site to various servers.

We have one page that is an account maintenance page that we want to use with a secure session (HTTPS:)

I do not want to hardcode the path in the href tag (i.e. <a href="https://www.website.com/account/index.html">

I have tried finding reference material but everything points to using a hard-coded approach.

Can I use a relative href declaration to use HTTPS: instead of HTTP: for a single page??

Much obliged!
Question by:EddieGomez
LVL 31

Accepted Solution

Frosty555 earned 1000 total points
ID: 23686468
That's a really good question. Unfortunately you can't... really. If you want to switch protocols you have to specify the full canonical URL. You'll run into the same problem if you try to link to a regular HTTP page from an HTTPS page. If you specify a relative URL, the HTTPS protocol will be assumed.

What you CAN do, though, is generate that full url using a server side language such as PHP, or by using server side includes.  See this person's forum post, which discusses a similar problem:

Example using server side includes:
<a href=http//<!--echo var='{HTTP_HOST}' -->/sitemap.html>Site Map</a>

Example using php:
<a href=http//<?PHP echo $_SERVER["DOCUMENT_ROOT"] ?>/sitemap.html>Site Map</a>

I think the document_root parameter is the one you want for PHP, but there's lots of other server variables related to the current URL that you might be able to try out. See PHP's manual:

I don't have an example using ASP, but I know it's possible.


Author Closing Comment

ID: 31548993
Thanks for the quick response!  I had a feeling it that would be the case.  You gave me some good ideas to go with.  Thanks a bunch!

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
Suggested Courses

834 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