1

(I'm using Wordpress HTTPS plugin to force Admin mode to run under HTTPS.
Its fine for Admin Panel.)

But still, once i'm under HTTPS mode, every front pages are broken because of, it is saying some front-pages Asset Files are coming as normal HTTP (without 'S') which are then getting blocked to load onto page.

Than resulted in rendering the page looking messy.

So to be more clear again,

  • When i call the site in HTTPS / SSL mode .. some asset files, like:
    • http://www.my-another-site.com/something.js
    • http://www.my-another-site.com/something.css
    • http://www.my-another-site.com/something.jpg
    • ... etc

.. are BROKEN. (Because i'm in https mode and those above files are coming as http)

So how to make Wordpress to FORCE LOAD those whatever files?
(I DON'T CARE WHETHER IT IS SECURE OR NOT. Just want the site under https://... to be rendering properly.)

| improve this question | | | | |
  • Install SSL Insecure Content Fixer and run the "test is_ssl()" test on its plugin menu row. That will test whether you're behind a reverse proxy, which stops WordPress detecting SSL. It will also offer a fix, depending on what it finds. – webaware Jul 29 '13 at 22:41
3

If assets are enqueued properly they are using the exact URL they are enqueued with. If the protocol in URL is hardcoded that causes mismatch issues you are seeing.

For proper protocol support enqueued URLs need to be either:

  • created with protocol-aware API function from WP API (most if not all functions that produce URLs are)
  • using protocol-relative format like //example.com/stylesheet.css

If you the links are coming from third party code you'll have to unregister and re-register resource accordingly or (worst case scenario if queue is not used) rewrite the code / have original developer do it.

| improve this answer | | | | |
2

Here's what I did to set up SSL for one of the clients.

1: Put this into wp-config.php in order to enable SSL on the admin side.

define('FORCE_SSL_ADMIN', true);
define('FORCE_SSL_LOGIN', true);

2: Make sure in Settings -> General the URL in both fields is preceeded by https://

3: Put this snippet (modified from this tutorial) into functions.php in order for all the internal non-HTTPS links to be redirected to their HTTPS equivalents.

function wpse_ssl_template_redirect() {
    if ( !is_ssl() ) {
        if ( 0 === strpos($_SERVER['REQUEST_URI'], 'http') ) {
            wp_redirect(preg_replace('|^http://|', 'https://', $_SERVER['REQUEST_URI']), 301 );
            exit();
        } else {
            wp_redirect('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 301 );
            exit();
        }
    }
}

add_action( 'template_redirect', 'wpse_ssl_template_redirect', 1 );
| improve this answer | | | | |
  • 1
    But how does this help with assets? – Rarst Jul 29 '13 at 13:54
  • 1
    The assets should get the https prefix by setting the URLs in Settings -> General, unless the links are hard-coded in the post content itself. – montrealist Jul 29 '13 at 14:10
  • 3
    If everything was set correctly, there wouldn't be a question... :) – Rarst Jul 29 '13 at 14:11
  • I want to redirect my old added images to the https. This is not working for me. – Bilal Hussain Jul 4 '17 at 5:48
0

I would recommend editing the .htaccess file or creating one.

Example including the default WordPress code:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE] 

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.