How to force the admin-ajax.php file to load over HTTPS?


I have a site that I’ve recently put 100% behind HTTPS. All assets on the front end and the back end are successfully being called over HTTPS, except admin-ajax.php.

This is causing any functionality that depends on the file to fail, including but not limited to CF7, Elementor and other Forms that use AJAX submission, etc.

The error I get, which you can see in the screenshot is “Mixed Content: The page at ‘‘ was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint ‘‘. This request has been blocked; the content must be served over HTTPS.”

here is what I’ve done so far to try to solve the issue.

1) Try everything at including define(‘FORCE_SSL_ADMIN’, true). Even though these are loading the wp-admin/admin-ajax.php file, this is happening from the front end.

2) Added the following to my apache config:

SetEnvIf X-Forwarded-Proto https HTTPS
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

3) use wp-cli to do a complete search and replace

sudo -u www-data wp search-replace '' '' --network

This replaced 151 items, even in the GUID column, which is highly advised against by WordPress. But it did not work. 0 instances of http:// remain in the database

4) Verified that site_url and home options correctly point to https://

Investigating the javascript code that causes the error shows that the code seems to be correctly calling ‘ajaxUrl’ variable. This variable should hold the https:// version of the file, right?

                    url: t.getSettings("ajaxUrl"), 
                    type: "POST",
                    dataType: "json",
                    data: t.getFormData(),
                    processData: !1,
                    contentType: !1,
                    success: t.onSuccess,
                    error: t.onError

The ajaxUrl variable is only returning the http version of the script. How else can I investigate this and ultimately fix it so that it loads over https?

mixed content error

user658182 4 months 0 Answers 18 views 0

Leave an answer