Community Forums › Forums › Archived Forums › General Discussion › Force https for specific pages
Tagged: https://
- This topic has 3 replies, 2 voices, and was last updated 9 years, 11 months ago by David Chu.
-
AuthorPosts
-
November 8, 2014 at 3:57 am #130883stl99Member
Hi,
This happens with the default WP theme and no plugins activated as well, after multiple WP consultants provided me with broken solutions or offered to set up outdated plugins for me, I'd like to try to ask here:
Basically I need to force https on specific pages while all other pages should still/only use http (https to http redirect).
The problem is that functions like this
//Force single page SSL
add_action( 'template_redirect', 'fb_ssl_template_redirect', 1 );
function fb_ssl_template_redirect() {if ( ( is_page(752) || is_page(17686) || is_page(19587) ) && !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();
}
} else 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();
}
}
}result in a redirect loop for the included pages.
Any ideas? I'm more than willing to pay for a solution, it just needs to work reliably and don't rely on plugins.
Cheers,
ThomasNovember 10, 2014 at 1:22 pm #131095David ChuParticipantHi,
When I do HTTPS for targeted pages, I don't use plugins, I do it at the server level instead.That's not to say that it's impossible to do it via PHP, but I just don't. Doing it outside of WP is simpler.
As you've seen, this is fairly breakable. Even doing it the way I do, if someone fools around with the URL by changing the permalink and/or the page title, that will also break, because the code cannot psychically know what the URL is. ๐
If multiple developers are not getting it done, you may have other difficulties. For instance, I don't do such changes on Windows servers, only on flavors of UNIX (which is much more common anyway). Also, if your host has some weird server setup that can't be altered by a developer, that could also prevent this from working, my method or the above method.
Hope that gives some ideas.
Dave
Dave Chu ยท Custom WordPress Developer – likes collaborating with Designers
November 10, 2014 at 2:30 pm #131103stl99MemberHi Dave,
Thanks a lot for your reply, fortunately there was one developer who could do it after all ๐
Cheers,
ThomasNovember 10, 2014 at 2:39 pm #131104David ChuParticipantCool!
That's not a tough fix for a decent coder. ๐Dave
Dave Chu ยท Custom WordPress Developer – likes collaborating with Designers
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.