Browsers do not try one protocol and then fall back to the other. The browser will use which ever protocol it is linked to. If that protocol isn't supported, the user will get an error.
If you want to force users to use one protocol, you can redirect from one to the other. For example, to force secure connection on your site use the following rewrite rule in your .htaccess. It will issue 301 redirects from http://example.com/page.html
to https://example.com/page.html
(source)
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R=301,L]
It sounds like you want to allow users to use either and to have them stay on the one they choose. That is fine. There are multilple ways that you can format relative links on your site to support that. Using //
is not the one that I would recommend.
If your user is on https://example.com/foo.html
and you want them to go to https://example.com/bar.html
, then any of the following href
will work in the a
tag:
- Full URL --
https://example.com/bar.html
-- If the user is on the http
site, it will bring them over to the https
site.
- Protocol relative --
//example.com/bar.html
-- The user will be directed to either https://example.com/bar.html
or http://example.com/bar.html
depending on which protocol they are currently using.
- Site relative --
/bar.html
-- Both the protocol and the domain name remain the same, the whole path in the URL changes.
- Directory relative --
bar.html
-- Replaces the document portion in the URL (everything after the last slash)
I recommend using site relative links that start with a single slash most of the time when linking to other things on your site. Like the protocol relative URLs, users will use the same http
or https
that they currently use. It is a lot less typing (and makes pages smaller) than using full urls or protocol relative URLs.
Directory relative URLs can also work but they can be tricky in a few cases:
- Linking from
example.com/bar/foo.html
to example.com/bar/
is tricky. The directory relative URL for that is ./
where the .
means 'current directory. The site relative URL is just /bar/
.
- Linking to the directory up uses
..
notation. So to link from example.com/bar/foo.html
to example.com/baz.html
the link would be ../baz.html
The server relative link would be just /baz.html
.
You may want to use directory relative links to link to other documents that are known to be in the current directory and use site relative links to link to JS, CSS, and images that are usually at or near the root of the site.
Protocol relative directives are most useful for linking to other sites where you want to preserve the protocol. I use that most often for third party JavaScript or images. If they are not fetched as secure, when my user is secure, the user gets a warning. If my user isn't secure, then it may make my site slower to to fetch resources from other sites securely. For example, if you were using currency data from my currency conversion site, you might link to its third party JavaScript like <script src="//coinmill.com/frame.js"></script>
All modern browsers and search engines support all of these types of links.