JavaScript http to https - Make browser request corresponding https URLs for http URLs, without needing to edit all pages and manually change all URLs to https? make http https,make http https apache

I am interested in switching my entire site from http over to https.

My concern is that I have some content that uses absolute http URLs.

I will need to edit each page in order to change those URLs to relative but that might take me a while to accomplish.

What I would like to know is if there is a way to use Javascript via the Google Tag Manager in order to re-write local absolute URLs to be HTTPS and not HTTP?

If this is possible, could it be used as a permanent solution?

Answer:1

One solution to consider is the Content Security Policy upgrade-insecure-requests directive.

The upgrade-insecure-requests directive instructs user agents to treat all of a site's unsecure URL's (those served over HTTP) as though they have been replaced with secure URL's (those served over HTTPS). This directive is intended for web sites with large numbers of unsecure legacy URL's that need to be rewritten.

It’d amount to configuring your Web server so all pages on your site get served with this header:

Content-Security-Policy: upgrade-insecure-requests

So the effect of adding that header would be: for any page at your site served with an https URL, any time a browser sees in one of those pages an http URL for an embedded (sub)resource —whether it be a URL for a stylesheet, script, image, video, or whatever—the browser will automatically (transparently) try to fetch the resource from the corresponding https URL instead.

For more details, you can see the Upgrade Insecure Requests spec.

2018-05-11 update

The upgrade-insecure-requests directive is now supported in all major browser engines (including Edge 17+ and Safari 10.3+):

https://caniuse.com/#feat=upgradeinsecurerequests

The downside of using it now is, so far it’s only supported in Firefox (since Firefox 42) and Chrome. But it also:


P.S., I work at the W3C, where we recently (finally) enabled TLS/https access to all W3C site resources—and since the W3C has hundreds of thousands (maybe millions) of pages with http URLs for embedded subresources, the way we were able to make it happen was in part by serving the Content-Security-Policy: upgrade-insecure-requests header across the entire site.

The article Supporting HTTPS and HSTS on w3.org gives more info about the deployment details.

Answer:2

I run this code in JavaScript: setTimeout(function(){console.log("1");}, 0); console.log("2"); But output is: 2 1 Why not vice versa?

I run this code in JavaScript: setTimeout(function(){console.log("1");}, 0); console.log("2"); But output is: 2 1 Why not vice versa?

I am looking for a little help in trying to retrieve the ID from an URL using JavaScript. I have a main menu system which looks like this <section id="menu"> <ul id="main"> <li id="...

I am looking for a little help in trying to retrieve the ID from an URL using JavaScript. I have a main menu system which looks like this <section id="menu"> <ul id="main"> <li id="...

I have an element with ng-class attribute like this: <label class="item item-input item-floating-label" ng-class="{'has-errors':{{loginForm.$submitted && loginForm['...

I have an element with ng-class attribute like this: <label class="item item-input item-floating-label" ng-class="{'has-errors':{{loginForm.$submitted && loginForm['...

  1. ngclass expressionchangedafterithasbeencheckederror
  2. ngclass expression example
  3. ngclass expression angular 6
  4. ngclass expression angular 7
  5. ngclass expression angular 2
  6. ng class with expression angular 4
  7. ng class expression if
  8. angularjs ng class expression
  9. ngclass expression array
  10. ng-class expression in angularjs
  11. ng-class expression conditional
  12. ng-class expression ternary
  13. ng-class expression multiple
  14. ng-class expression not working
  15. ng-class expression if else
  16. ng-class expression concatenate
  17. ng-class expression function
  18. ng-class expression not updating
  19. ng-class expression angular
  20. ng-class expression syntax

Setting width for <li> tags not working. Width is changing based on content for <li> tag below is the html code Without using display: block/table/inline-block; <!DOCTYPE ...

Setting width for <li> tags not working. Width is changing based on content for <li> tag below is the html code Without using display: block/table/inline-block; <!DOCTYPE ...

  1. javascript setting width of element
  2. javascript setting width