Force https on Wordpress multisite - wordpress

I've got a Wordpress multisite and I'm trying to force https programmatically (better than via .htaccess as htaccess has many rules, set from cache plugin and the multisite itself).
The code I'm using is this one:
if ( FORCE_HTTPS && (!isset($_SERVER['HTTPS']) || strtolower($_SERVER['HTTPS']) != 'on' ))
{
//echo("Location: " . "https://" . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]);
header("Location: " . "https://" . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]);
exit();
}
It's working properly in main site but not in subdmoains, but curiously is I type https://subsite.domain.com it works properly, but if I go with this redirection I see a blank page.
The certificate is working properly and as I sayed, if I type the full adress I see everything ok
What's going wrong or how can I force https?
Thank you

validate your server ssl for errors:
http://www.digicert.com/help/
use this wp plugin:
http://wordpress.org/plugins/force-ssl-everywhere/
ssl on logged in

Related

HTTPS Issue With Mixed Content - ARForms Plugin

I have a site wordpress in HTTPS, but also i have an Mixed Content because of ARForms Plugin. PHP 5.6
fonts.googleapis.com and some images in this plugin unsecure, and that files i cant find in database anf template files, please help me by PHP.
Thank you.
This is what i found in configuration and this functional not work:
$arfsiteurl = home_url();
if (is_ssl() and ( !preg_match('/^https:\/\/.*\..*$/', $arfsiteurl) or ! preg_match('/^https:\/\/.*\..*$/', WP_PLUGIN_URL))) {
$arfsiteurl = str_replace('http://', 'https://', $arfsiteurl);
define('ARFURL', str_replace('http://', 'https://', WP_PLUGIN_URL . '/arforms'));
} else {
define('ARFURL', WP_PLUGIN_URL . '/arforms');
}
You should try to download these scripts locally and enqueue them with your HTTPS secure server.
As for the plugin scripts, you could also try to install this plugin and click the flush rewrite rules for it to automatically add code into your .htaccess file.

Wordpress redirection issue , any http url redirects to https homepage

I m using IIS and I have a wordpress installation and SSL installed. Any url requests which include http (eg: http://example.com/fooBar), redirects to https://example.com homepage.I expect http://example.com/fooBar redirects to https://example.com/fooBar. What am i missing?
Also, I am open for hardcoded solutions. Honestly i have 2 specific http urls to redirect to their https versions.
You may add this on your functions.php
add_action('template_redirect', 'redirect_core', 50);
add_action('init', 'redirect_core', 50);
add_action('wp_loaded', 'redirect_core', 50);
function redirect_core(){
if (!is_ssl()) {
wp_redirect('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 301);
exit();
}
}
or use this plugin: HTTPS Redirection
To fix this you will need to edit the sites 'Base URL' to include 'https'. This can be done by going to your admin panel>General Settings and updating the 'WordPress Address (URL)' and the 'Site Address (URL)'. Make sure that your .htaccess has the correct permissions set for this to take effect.

get_template_directory_uri() returns http instead of https on SSL site

I know the topic has been already discussed, but it seems no solution was found. This is my case:
I have a wordpress site which now has SSL. However, in the theme resources are added as follows:
wp_enqueue_script( 'spectrumwp-conditional', get_template_directory_uri() . '/js/vendor/conditional.js', array('jquery'), null, true);
but get_template_directory_uri() returns the url with http not https.
Can you help me to solve this?
Edit:
I added this to my wp-config.php file
$_SERVER['HTTPS']='on';
Links to resources are shown with https:// but instead of, for example
https://www.exaple.com/wp-content/plugins/...
I have
https://www.example.com/plugins/LayerSlider/...
e.g. wp-content folder is missing
Final update:
uncommenting
define('FORCE_SSL_ADMIN', true);
and adding
if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false)
{ $_SERVER['HTTPS']='on'; }
just before the line
/* That's all, stop editing! Happy blogging. */
fixed the problem! Only, I recommend $_SERVER['HTTP_X_FORWARDED_PROTO'] is not used, as it may not be accurate enough.
Solved!
You need to use is_ssl() to check if the site is running https:// or http://
Here is the hook to check and redirect :
function check_if_https() {
if ( !is_ssl() ) {
wp_redirect('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 301 );
exit();
}
}
add_action ( 'template_redirect', 'check_if_https', 1 );
Go into Settings -> General and check the Site URL.
It sounds like the problem you're having is this value is still HTTP, not HTTPS. Approach this change with caution. Make sure you have a working backup and a full understanding of why this URL needs to change as well as the impact it will have.
get_template_directory_uri() will automatically provide a HTTPS link when site URL is set correctly.

Wordpress plugin, do not prepend host in wp_register_script

I am pretty new to WP and have a little question about the wp_register_script function,.
I have a dev environment where the url is test.example.com .. right know when i make a plugin and use wordpress wp_register_script to insert the .js and .css files wordpress prepend the host in front of the url ..
Is there a good way to handle this?? without creating a test DB and change the "siteurl" ?
I found a workaround for my issue ..
I could set WP_SITEURL in the we-config.php file (not the best solution)
if(isset($_SERVER['HTTP_HOST']) && $_SERVER['HTTP_HOST'] == "test.example.com") {
define('WP_SITEURL','http://test.example.com'); // use this if we are testing on test.skala.fm (not localhost)
define('ENVIRONMENT', 'local'); // using localdb
//define('ENVIRONMENT', 'production'); // use this if we are testing on test.example.com (not localhost)
} else {
define('ENVIRONMENT', 'production');
}

Decoding failed: Syntax error Magento

Hi I have use a magento wordpress single sigin plugin , for this in installation it is suggested to add this code in magento index file .
// for wordpress login
$adminwp = "/var/www/projects/magentowoo/index.php/admin";
$wploadwp = "/var/www/projects/arun/rohitgoel/wp-load.php";
$uri = $_SERVER['REQUEST_URI'];
//echo $uri;
if(!strpos($uri, $adminwp) && !strpos($uri, 'downloader')) {
require_once($wploadwp);
}
it works fine but it a strange issue, when i am adding the product image in admin it gives a error
Decoding failed: Syntax error
i have try to comment out this code and than image works properly. Please suggest how can i fix this
Update your browser Flash version, if Flash is being blocked by the browser as being outdated this error will occur on the website.

Resources