我想在我的一些页面(带有表单的页面)上强制建立安全连接,但我不希望整个网站都使用ssl(降低速度)
有没有办法将特定页面配置为需要ssl?
我想在我的一些页面(带有表单的页面)上强制建立安全连接,但我不希望整个网站都使用ssl(降低速度)
有没有办法将特定页面配置为需要ssl?
使用admin ssl插件。对于wp之外的内容,请在apache中使用Rewrite规则
新工作流,因为不支持Admin SSL插件。
使用插件WP https
如果需要SSLwp-admin
, 将此添加到wp-config.php
:
define( \'FORCE_SSL_ADMIN\', TRUE );
wp-config.php
define( \'FORCE_SSL_LOGIN\', TRUE );
.htaccess
; 删除WP的默认值<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
</IfModule>
如果在前端将特定页面/帖子设置为SSL,则使用以下插件或在帖子/页面编辑器中设置选项;只有当你激活了这个插件WP https的可能性。另见Gist 4081291 对于示例插件/**
* Plugin Name: Force SSL for specific pages
* Description:
* Author: Frank Bültge
* Author URI: http://bueltge.de/
* Version: 1.0.0
*/
! defined( \'ABSPATH\' ) and exit;
if ( ! function_exists( \'fb_force_ssl\' ) ) {
add_filter( \'force_ssl\' , \'fb_force_ssl\', 1, 3 );
function fb_force_ssl( $force_ssl, $id = 0, $utrl = \'\' ) {
// A list of posts/page that should be SSL
$ssl_posts = array( 22, 312 );
if ( in_array( $id, $ssl_posts ) )
$force_ssl = TRUE;
return $force_ssl;
}
} // end if func exists
无插件WordPress HTTPSadd_action( \'template_redirect\', \'fb_ssl_template_redirect\', 1 );
function fb_ssl_template_redirect() {
if ( is_page( 123 ) && ! 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_page( 123 ) && 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();
}
}
}
add_filter( \'pre_post_link\', \'fb_set_ssl_url\', 10, 3 );
function fb_set_ssl_url( $permalink, $post, $leavename ) {
if ( 123 == $post->ID )
return preg_replace( \'|^http://|\', \'https://\', $permalink );
return $permalink;
}
对于WordPress 3.0及以上版本,admin ssl插件不起作用。为了让SSL正常工作,您需要采取两个步骤:
在wp配置中启用SSL管理选项。php文件(see here).WPSSL 网站上的插件。(针对WordPress 3.0+)更新)在要通过SSL运行的页面上,添加名为“force\\u SSL”的元标记,并将值设置为“true”
尝试Better WP Security 插件。除了一系列有助于保护网站安全的调整外,它还提供了一些设置,允许您通过添加到可视化编辑器中的选择框,强制将ssl连接到登录页面或整个后端(如果您选择),以及每个内容的前端所选页面。非常容易使用。
当然,您必须首先在服务器上设置SSL,这意味着您必须安装自签名证书(不推荐),或者从第三方机构购买证书并将其安装到服务器上。
我对你的解决方案有很多问题(但它帮助了我)。对于以下情况,我将在此处列出我的解决方案:
vestacp上的Wordpress multisite服务器运行在带有nginx代理的apache上。首先,我只使用了这个WP扩展:“SSL不安全内容修复程序”,它可以处理WPMU,以及“混合内容”错误(因为“Wordpress Https”已被弃用,不适用于我)
。其次,is\\u ssl()函数不适用于nginx代理,因此我使用了这个函数:
function isSecure() {
return
(!empty($_SERVER[\'HTTPS\']) && $_SERVER[\'HTTPS\'] !== \'off\')
|| $_SERVER[\'SERVER_PORT\'] == 443;
}
。而且“is_page()”不起作用,所以这是我的最终代码(用于将特定页面重定向到https)add_action( \'template_redirect\', \'fb_ssl_template_redirect\', 1 );
function fb_ssl_template_redirect() {
global $post;
//login = 8886
//Pages clients
$array_posts_ssl = array(8886);
$array_posts_ssl_parents = array(8886);
if ( in_array($post->ID,$array_posts_ssl) ) {
if ( !isSecure() ) {
wp_redirect(\'https://\' . $_SERVER[\'HTTP_HOST\'] . $_SERVER[\'REQUEST_URI\'], 301 );
exit();
}
} else {
if ( isSecure() ){
wp_redirect(\'http://\' . $_SERVER[\'HTTP_HOST\'] . $_SERVER[\'REQUEST_URI\'] , 301 );
exit();
}
}
}
上面提到的两个插件似乎都过时了,或者至少暂时没有维护过。这个WordPress-https plugin 这似乎是最好的选择,它将在整个站点或某些页面上强制使用ssl。
下面是最好的“WordPress”方式,我已经对它进行了充分的评论,请您解释它的作用。
add_action(\'wp\',\'_my_custom_ssl_redirect\'); // the \'wp\' hook is the first place the post id is set.
function _my_custom_ssl_redirect(){
global $post,$wp; // get some global values.
$page_ids = array(2,123,321,456); // array of page ids we want to force to ssl.
if( is_page() && isset($post->ID) && in_array($post->ID,$page_ids) ){ // check we are on a page and its a page we want to redirect.
wp_safe_redirect( // make sure we only redirect to "internal" urls.
add_query_arg( // add any url query arguments back to the url.
$_SERVER[\'QUERY_STRING\'], // The current query args.
\'\',
trailingslashit( // add a trailing slash to the home url as sometimes it is not added.
home_url( $wp->request, "https" ), // get the home url HTTPS link.
301 // set the redirect to be 301 "permanent", you can use 302 "temporary" here instead.
)
)
);
exit; // exit ASAP, no point in loading anything more.
}
}
整洁的非注释版本:)(完全相同的代码)add_action(\'wp\',\'_my_custom_ssl_redirect\');
function _my_custom_ssl_redirect(){
global $post,$wp;
$page_ids = array(2,123,321,456); // array of page ids we want to force to ssl.
if( is_page() && isset($post->ID) && in_array($post->ID,$page_ids) ){
wp_safe_redirect( add_query_arg( $_SERVER[\'QUERY_STRING\'], \'\',trailingslashit(home_url( $wp->request, "https" ), 301 )) );
exit;
}
}
我已经在新安装的WordPress上设置了多站点。然后我创建了一些其他网站,所以,最后,我有了这样的东西http://example.comhttp://site1.example.comhttp://site2.example.comhttp://site3.example.com然后我安装了SSL数字证书,因此我更改了网站的URL以匹配HTTPS方案:http://example.com更改我转到的方案Sites > All Sites, 然后单击每个站点,在选项卡“信息”(第一个)中,我只需更
我想在我的一些页面(带有表单的页面)上强制建立安全连接,但我不希望整个网站都使用ssl(降低速度)
有没有办法将特定页面配置为需要ssl?
使用admin ssl插件。对于wp之外的内容,请在apache中使用Rewrite规则
新工作流,因为不支持Admin SSL插件。
使用插件WP https
如果需要SSLwp-admin
, 将此添加到wp-config.php
:
define( \'FORCE_SSL_ADMIN\', TRUE );
wp-config.php
define( \'FORCE_SSL_LOGIN\', TRUE );
.htaccess
; 删除WP的默认值<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
</IfModule>
如果在前端将特定页面/帖子设置为SSL,则使用以下插件或在帖子/页面编辑器中设置选项;只有当你激活了这个插件WP https的可能性。另见Gist 4081291 对于示例插件/**
* Plugin Name: Force SSL for specific pages
* Description:
* Author: Frank Bültge
* Author URI: http://bueltge.de/
* Version: 1.0.0
*/
! defined( \'ABSPATH\' ) and exit;
if ( ! function_exists( \'fb_force_ssl\' ) ) {
add_filter( \'force_ssl\' , \'fb_force_ssl\', 1, 3 );
function fb_force_ssl( $force_ssl, $id = 0, $utrl = \'\' ) {
// A list of posts/page that should be SSL
$ssl_posts = array( 22, 312 );
if ( in_array( $id, $ssl_posts ) )
$force_ssl = TRUE;
return $force_ssl;
}
} // end if func exists
无插件WordPress HTTPSadd_action( \'template_redirect\', \'fb_ssl_template_redirect\', 1 );
function fb_ssl_template_redirect() {
if ( is_page( 123 ) && ! 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_page( 123 ) && 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();
}
}
}
add_filter( \'pre_post_link\', \'fb_set_ssl_url\', 10, 3 );
function fb_set_ssl_url( $permalink, $post, $leavename ) {
if ( 123 == $post->ID )
return preg_replace( \'|^http://|\', \'https://\', $permalink );
return $permalink;
}
对于WordPress 3.0及以上版本,admin ssl插件不起作用。为了让SSL正常工作,您需要采取两个步骤:
在wp配置中启用SSL管理选项。php文件(see here).WPSSL 网站上的插件。(针对WordPress 3.0+)更新)在要通过SSL运行的页面上,添加名为“force\\u SSL”的元标记,并将值设置为“true”
尝试Better WP Security 插件。除了一系列有助于保护网站安全的调整外,它还提供了一些设置,允许您通过添加到可视化编辑器中的选择框,强制将ssl连接到登录页面或整个后端(如果您选择),以及每个内容的前端所选页面。非常容易使用。
当然,您必须首先在服务器上设置SSL,这意味着您必须安装自签名证书(不推荐),或者从第三方机构购买证书并将其安装到服务器上。
我对你的解决方案有很多问题(但它帮助了我)。对于以下情况,我将在此处列出我的解决方案:
vestacp上的Wordpress multisite服务器运行在带有nginx代理的apache上。首先,我只使用了这个WP扩展:“SSL不安全内容修复程序”,它可以处理WPMU,以及“混合内容”错误(因为“Wordpress Https”已被弃用,不适用于我)
。其次,is\\u ssl()函数不适用于nginx代理,因此我使用了这个函数:
function isSecure() {
return
(!empty($_SERVER[\'HTTPS\']) && $_SERVER[\'HTTPS\'] !== \'off\')
|| $_SERVER[\'SERVER_PORT\'] == 443;
}
。而且“is_page()”不起作用,所以这是我的最终代码(用于将特定页面重定向到https)add_action( \'template_redirect\', \'fb_ssl_template_redirect\', 1 );
function fb_ssl_template_redirect() {
global $post;
//login = 8886
//Pages clients
$array_posts_ssl = array(8886);
$array_posts_ssl_parents = array(8886);
if ( in_array($post->ID,$array_posts_ssl) ) {
if ( !isSecure() ) {
wp_redirect(\'https://\' . $_SERVER[\'HTTP_HOST\'] . $_SERVER[\'REQUEST_URI\'], 301 );
exit();
}
} else {
if ( isSecure() ){
wp_redirect(\'http://\' . $_SERVER[\'HTTP_HOST\'] . $_SERVER[\'REQUEST_URI\'] , 301 );
exit();
}
}
}
上面提到的两个插件似乎都过时了,或者至少暂时没有维护过。这个WordPress-https plugin 这似乎是最好的选择,它将在整个站点或某些页面上强制使用ssl。
下面是最好的“WordPress”方式,我已经对它进行了充分的评论,请您解释它的作用。
add_action(\'wp\',\'_my_custom_ssl_redirect\'); // the \'wp\' hook is the first place the post id is set.
function _my_custom_ssl_redirect(){
global $post,$wp; // get some global values.
$page_ids = array(2,123,321,456); // array of page ids we want to force to ssl.
if( is_page() && isset($post->ID) && in_array($post->ID,$page_ids) ){ // check we are on a page and its a page we want to redirect.
wp_safe_redirect( // make sure we only redirect to "internal" urls.
add_query_arg( // add any url query arguments back to the url.
$_SERVER[\'QUERY_STRING\'], // The current query args.
\'\',
trailingslashit( // add a trailing slash to the home url as sometimes it is not added.
home_url( $wp->request, "https" ), // get the home url HTTPS link.
301 // set the redirect to be 301 "permanent", you can use 302 "temporary" here instead.
)
)
);
exit; // exit ASAP, no point in loading anything more.
}
}
整洁的非注释版本:)(完全相同的代码)add_action(\'wp\',\'_my_custom_ssl_redirect\');
function _my_custom_ssl_redirect(){
global $post,$wp;
$page_ids = array(2,123,321,456); // array of page ids we want to force to ssl.
if( is_page() && isset($post->ID) && in_array($post->ID,$page_ids) ){
wp_safe_redirect( add_query_arg( $_SERVER[\'QUERY_STRING\'], \'\',trailingslashit(home_url( $wp->request, "https" ), 301 )) );
exit;
}
}
所以我把一个插件放在一起,它允许我用一个在线服务连接多个客户端站点。我可以让服务供应商代码段加载,但一旦你与它交互,事情就会变得棘手,它拒绝加载(我猜)iframe。。。它的文档记录很差。Refused to load https://www.service-domain.com/ because it does not appear in the frame-ancestors directive of the Content Security Policy.这是我收到的控制台日志错误。因此,我跳回插件