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

Posted on 2009-02-19
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="">

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

    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

    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

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
    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…
    In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…
    In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…

    734 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

    25 Experts available now in Live!

    Get 1:1 Help Now