php WP为非常旧的浏览器/操作系统禁用SSL / CDN(Windows XP,Mac OS Lion / Snow Leopard)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php WP为非常旧的浏览器/操作系统禁用SSL / CDN(Windows XP,Mac OS Lion / Snow Leopard)相关的知识,希望对你有一定的参考价值。

# BEGIN SEDWEB OLDBROWSER SUPPORT
<IfModule mod_rewrite.c>
RewriteEngine On

# disable cdn for very old browsers
RewriteCond %{HTTP_USER_AGENT} Windows\sNT\s5
RewriteCond %{HTTP_USER_AGENT} Mac\sOS\sX\s10_6
RewriteCond %{HTTP_USER_AGENT} Mac\sOS\sX\s10_7
RewriteRule ^(.*)$ $1?swcdn_without_cdn=1 [QSA]

# disable https for very old browsers
RewriteCond %{HTTP:X-Forwarded-Proto} =https
RewriteCond %{HTTP_USER_AGENT} Windows\sNT\s5
RewriteCond %{HTTP_USER_AGENT} Mac\sOS\sX\s10_6
RewriteCond %{HTTP_USER_AGENT} Mac\sOS\sX\s10_7
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
# END SEDWEB OLDBROWSER SUPPORT

# HTTPS forced by SG-Optimizer
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_USER_AGENT} !Windows\sNT\s5
RewriteCond %{HTTP_USER_AGENT} !Mac\sOS\sX\s10_6
RewriteCond %{HTTP_USER_AGENT} !Mac\sOS\sX\s10_7
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
</IfModule>
# END HTTPS
<?php
/* NO HTTPS FOR OLD BROWSERS */
function is_user_agent_too_old_for_ssl(){

	if( ! isset( $_SERVER['HTTP_USER_AGENT'] ) ){
		return false;
	}

	// windows xp
	if( strpos( $_SERVER['HTTP_USER_AGENT'], "Windows NT 5.1" ) !== false ){
		return true;
	}
	// mac lion (2011)
	if( strpos( $_SERVER['HTTP_USER_AGENT'], "Mac OS X 10_7" ) !== false ){
		return true;
	}
	// mac snow leopard (2009)
	if( strpos( $_SERVER['HTTP_USER_AGENT'], "Mac OS X 10_6" ) !== false ){
		return true;
	}

	return false;
}
if( is_user_agent_too_old_for_ssl() ){
	add_action( 'init', function(){
		if( is_ssl() ){
			global $wp;
			wp_redirect( str_replace( 'https://', 'http://', home_url( $wp->request ) ) );
			exit;
		}

		// add_filter( 'wp_redirect', function( $location, $status ){
		// 	$current_url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
		// 	if( $current_url === $location ){
		// 		return false;
		// 	}
		// 	if( $current_url === str_replace( 'https:', 'http:', $location ) ){
		// 		return false;
		// 	}

		// 	return $location;
		// }, PHP_INT_MAX, 2 );
	} );

	ob_start();
	add_action('shutdown', function() {
	    $final = '';

	    // We'll need to get the number of ob levels we're in, so that we can iterate over each, collecting
	    // that buffer's output into the final output.
	    $levels = ob_get_level();

	    for ($i = 0; $i < $levels; $i++) {
	        $final .= ob_get_clean();
	    }

	    // Apply any filters to the final output
	    echo apply_filters('final_output', $final);
	}, 0);
	add_filter('final_output', function($output) {
	    return str_replace('https:', 'http:', $output);
	});

	// add_filter( 'option_active_plugins', function( $plugins ){
	// 	if( strpos( $_SERVER['HTTP_USER_AGENT'], "Windows NT 5.1" ) !== false ){
	// 		$key = array_search( 'ssl-insecure-content-fixer/ssl-insecure-content-fixer.php', $plugins );
	// 		if( $key !== false ){
	// 			unset( $plugins[ $key ] );
	// 		}
	// 	}

	// 	return $plugins;
	// } );
}

<?php
/* support for very old browsers */
if( $_SERVER['SERVER_PORT'] !== '443' ){
	/* we are here only if .htaccess did not redirect the page to https */
	/* this can happen olny for very old browsers filtered via .htaccess rules */
	$__siteurl = 'http://'.$_SERVER[ 'HTTP_HOST' ];
	define( 'WP_SITEURL', $__siteurl );
	define( 'WP_HOME', $__siteurl );
}

以上是关于php WP为非常旧的浏览器/操作系统禁用SSL / CDN(Windows XP,Mac OS Lion / Snow Leopard)的主要内容,如果未能解决你的问题,请参考以下文章

php WP SSL

通过 wp-config.php 在 wordpress 上正确强制 SSL

php 禁用WP Cron

php 禁用帖子菜单wp

php 禁用JSON WP Rest API

php WP Mail SMTP:禁用SMTPAutoTLS