JS and CSS files not being included with HTTPS

Posted in: Newspaper
Post count: 38

I have moved my site over to HTTPS. I have altered the DB as i usually do to add https to the url. This has updated all of the URLs on the site, but all of the CSS and JS files are being blocked because they are being included as http files. I dont think its a major error, but based on the help i have gotten so far people are blaming the theme for this. I have checked header.php and functins and there are no lines that could be causing this.

In rooting through header.php i found <?php echo td_global::$http_or_https?>. What triggers this to be https? Is this the cause of the site not including external files as https?

Post count: 9544

What helps immensely is
a) make sure you change your site URL to https in the WP site setting (obviosuly)
b) add an explicit setting for the URL in the wp-config.php file for https (path to site)
c) use wp-optimize to clear all “transients” and clear all other cache
d) make sure you set up a site-wide 301 wildcard redirect in your htaccess so any request for http actually loads https version for “anything”

Any theme stuff should “pick up” the https setting if you put it into the wp-config.php file. (In theory.)

We did this in Nov 2014 and went through some of the same issues.

Post count: 38

Hi Chris,

Thanks for the response. I tried putting a wildcard redirect and it ended up giving me a redirect loop error. This same thing happens when i use define(‘FORCE_SSL_LOGIN’, true);

In order to test this without bringing the site down i have implemented the following. Its working, bar the mismatch issues with the css and js. if i can figure out what causes the redirect loop on the login page it should sort the same issue when i put the global redirect

if ($_SERVER[‘HTTP_X_FORWARDED_PROTO’] == “https”)
{
define(‘WP_HOME’, ‘https://&#8217; . $web_site_url);
define(‘WP_SITEURL’,’https://&#8217; . $web_site_url);
//define(‘FORCE_SSL_LOGIN’, true);
}
else
{
define(‘WP_HOME’, ‘http://&#8217; . $web_site_url);
define(‘WP_SITEURL’,’http://&#8217; . $web_site_url);
}

Post count: 9544

It’s an adventure, sadly 🙂

Did you add the explicit link to your https website in your wp-config.php file ?
https://codex.wordpress.org/Editing_wp-config.php

define('WP_HOME', 'https://www.mysite.ooo');
define('WP_SITEURL', 'https://www.mysite.ooo');

*(we use www – you might not be; but that has to be consistent too – either all www or no www; not both)

And “obviously” resave your permalinks from wp admin panel after you add that. Clear cache. Clear transients!

I’m using Apache, so if you’re using something else not sure my htaccess code will help, but here is what we use for global https redirect:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,QSA]
</IfModule>

Google article if not already read
https://support.google.com/webmasters/answer/6073543?hl=en

  • This reply was modified 10 years by simchris.
  • This reply was modified 10 years by simchris.
  • This reply was modified 10 years by simchris.
  • This reply was modified 10 years by simchris.
  • This reply was modified 10 years by simchris.
Post count: 38

adventure is one way to describe it! i have it working to a degree. if i change the url in the browser to https the page loads fine, but if i use the htaccess redirect i still get the redirect loop. this is the most difficult setup of ssl ive ever had!

Post count: 9544

If you add the https to the wp-config.php you likely don’t need the htaccess addition; just resave permalinks.

As WordPress should automatically rewrite all requests to https, based on seeing in the config that all pages should load as https.

Sorry, we have mix of static and wordpress, hence we need that addition.

For “only wordpress” the built in rewrite rule written by WordPress to the htaccess file will work, once you save your permalinks.

Post count: 38

Im not sure what is going on, but the normal code to detect whether the connection is https using htaccess does not work for me. Everything i try just messes up. According to apache the connection is on port 80 even though i have the green padlock in the nav bar. Anyway i was able to make it work using php as there was one consistent variable that was working for me.

This should be a search engine friendly option right? I put this at the top of index.php in the wordpress root so it is the first thing that it will process.

if($_SERVER[‘HTTP_X_FORWARDED_PROTO’] == “http”)
{
header(“HTTP/1.1 301 Moved Permanently”);
header(“Location: https://&#8221;.$_SERVER[‘HTTP_HOST’].$_SERVER[‘REQUEST_URI’]);
die();
}

Viewing 7 posts - 1 through 7 (of 7 total)
The forum ‘Newspaper’ is closed to new topics and replies.