jeroen jeroen - 1 year ago 76
HTML Question

Short way to link to http from https (and vice versa) using relative links

When I´m in a secure part of a web-site I´m developing (entering a specific page or folder using https), the relative links to the normal pages are automatically converted to https as well.

Is there a way to tell an <a> tag to always use the http protocol instead of the https protocol (or the other way around)?

I know it´s easy using the complete link ( or, but I would like it to work with relative links (index.html, ../index.html, etc.).

Answer Source

We use Apache mod_rewrite to control whether a page is served via http or https. Here's an example snippet from a site's root directory .htaccess file:

# Redirect most reqests for https to http
RewriteRule ^*)$1 [R=301,NC]

# Allow some URIs to be https if requested
RewriteCond   %{SERVER_PORT}  ^443$
RewriteCond   %{REQUEST_URI}  !^/images/(.*)$
RewriteCond   %{REQUEST_URI}  !^/scripts/(.*)$
RewriteCond   %{REQUEST_URI}  !^/styles/(.*)$
RewriteCond   %{REQUEST_URI}  !^/store(.*)$
RewriteCond   %{REQUEST_URI}  !^/login.htm$
RewriteRule ^(.*)$1 [L,R]

# Force some URIs to be https only
RewriteCond   %{SERVER_PORT}  ^80$
RewriteRule ^store(.*)$1 [L,R]

RewriteCond   %{SERVER_PORT}  ^80$
RewriteRule ^FormSanityKey.htm$1 [L,R]

Read all about it at:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download