HTTP request to an API has been blocked from an HTTPS website

HTTP request to an API has been blocked from an HTTPS website - .htaccess files are extremely useful in many cases for users who either do not have root permissions or for users who simply aren't comfortable in making changes in their web server's configuration file. Trying to debug .htaccess not working isn't always the easiest thing to do, however, hopefully by checking the discuss below mentioned about htaccess, https, http, web-services, .htaccess common problems as well as the troubleshooting tips, you'll have a better grasp on what you may have to modify to get your .htaccess file running smoothly.Problem :


I am facing problem to call web service which is hosted over HTTP and I am calling web service from HTTPS domain.



web service's .htaccess



RewriteEngine On 
RewriteCond %REQUEST_FILENAME !-f
RewriteRule ^(.*)$ %ENV:BASEindex.php [QSA,L]


I got following error in console when I am trying to calling web.




angular.min.js:93 Mixed Content: The page at https://www.<my-domain.com>/#/ was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint http://<api url goes here>. This request has been blocked; the content must be served over HTTPS.




Note



Web service is hosted in AWS server which is HTTP only and my website is hosted to other hosting provider.


Solution :

As a work around, I am proxying the web service:




  1. My SSL Hosting (Angular Project + Newly created proxy web service)


  2. AWS (Old Web service + MySql Database)




From angularJS i call newly created proxy (that just uses cURL). This cURL code passes request to AWS server over HTTP.


Additionally, if you would like to do some further testing, give the htaccess tester tool a try. It allows you to specify a certain URL as well as the rules you would like to include and then shows which rules were tested, which ones met the criteria, and which ones were executed.

Comments

Popular posts from this blog

Rewrite in Mediawiki, remove index.php, .htaccess

.htaccess rewrite wildcard folder paths from host

Using .htaccess to set a cookie and 301 redirect