我会根据服务器配置执行此操作。下面是.htaccess
:
RewriteCond %{HTTP_HOST} !^blog\\.example\\.com$
RewriteRule (.*)\\.html$ http://blog.example.com/$1.html [L,R=301]
你也可以在WordPress插件中这样做。未经测试的建议:
add_action( \'template_redirect\', \'wpse_77279_redirect\' );
function wpse_77279_redirect()
{
if ( is_single()
and \'blog.example.com\' !== $_SERVER[\'HTTP_HOST\']
and \'post\' === get_post_type()
)
{
wp_redirect( \'blog.example.com\' . $_SERVER[\'REQUEST_URI\'] );
exit;
}
}