www.webdeveloper.com
Results 1 to 10 of 10

Thread: Link relatively to https

  1. #1
    Join Date
    Jan 2011
    Posts
    12

    Link relatively to https

    This is nagging me really..
    How do you construct a menusystem that links relatively from a http to https ?

    Since it has to relative there can not be any https://hostname/ at the start.

    Are there no means to get around this ?

  2. #2
    Join Date
    Mar 2011
    Posts
    1,133
    No. By definition, a relative link is based on the location of the parent document. The browser then constructs the complete URL using that information. Good luck!
    Rick Trethewey
    Rainbo Design

  3. #3
    Join Date
    Jan 2011
    Posts
    12
    Yes, I've learned that by now.

    But aren't there any meas to dynamically switch the 'base' (http or https) dynamically ?
    Javascript ?

  4. #4
    Join Date
    Mar 2011
    Posts
    1,133
    Yes, you could change all of the links on a page or just those within a particular section to use https with Javascript. It wouldn't be a trivial piece of code because you'd have to check each href attribute to see if it was pointing to your domain or an external site. And, of course, you'd have to deal with turning relative URLs into complete URLs. But it could be done.

    It would be much simpler to use JavaScript to detect if the page was loaded with http and then self-redirect it using https. Then all of the internal links on that page would be using https, both relative and complete URLs.

    Good luck!
    Rick Trethewey
    Rainbo Design

  5. #5

  6. #6
    Join Date
    Aug 2011
    Posts
    21
    if it is ok just keep the Https:// portion to limited secure pages where it is require and if there is a duplicate URL with https:// which can be crawled then block that url otherwise there may be an issue of duplication

  7. #7
    Join Date
    Oct 2011
    Posts
    1
    if it is ok just keep the Https:// portion to limited secure pages where it is require and if there is a duplicate URL with https:// which can be crawled then block that url otherwise there may be an issue of duplication

    _________________

  8. #8
    The advantage of hard coding an HTTPS based URL is that you will have already loaded the resource (e.g. javascript) in the HTTP part of the your site ready for use in the HTTPS part.Assuming that you cache everything except HTML the cached resource can be used in HTTPS part of your site with no network round trip.
    -------------------------------
    Moderator says: no links toward commercial sites are allowed. Next time you risk to be banned

  9. #9
    you can use a custom middleware to redirect from https to http (or vice versa) for centrain URLs or URL patterns. This could also be done in Apache (or other web server) configuration.

    ----------------------------

  10. #10
    Join Date
    Oct 2005
    Posts
    843
    As rtrethewey said, you could use Javascript to do what you want, it wouldn't be too overly complex to do a a simple loop to loop through all page links on the page load and update the href depending on what its currently set to and what the browser location is at.

    That's the only real way to dynamically switch the base url of your links.

    Or just force them to the https side of your website.
    Welsh

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles