Last active
April 16, 2018 18:25
-
-
Save estevecastells/830275d0d530b4ed1f0e346d4c6de8b8 to your computer and use it in GitHub Desktop.
Force HTTP only via .htaccess or PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* Redirect WordPress front end https URLs to http without a plugin | |
* Necessary when running forced SSL in admin and you don't want links to the front end to remain https. | |
* @link http://blackhillswebworks.com/?p=5088 | |
*/ | |
add_action( 'template_redirect', 'bhww_ssl_template_redirect', 1 ); | |
function bhww_ssl_template_redirect() { | |
if ( is_ssl() && ! is_admin() ) { | |
if ( 0 === strpos( $_SERVER['REQUEST_URI'], 'http' ) ) { | |
wp_redirect( preg_replace( '|^https://|', 'http://', $_SERVER['REQUEST_URI'] ), 301 ); | |
exit(); | |
} else { | |
wp_redirect( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 301 ); | |
exit(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RewriteEngine On | |
RewriteCond %{HTTPS} on | |
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment