我如何隐藏我使用的WordPress(带有W3 Total缓存)

时间:2011-08-09 作者:baritoneuk

出于安全考虑,我不希望我使用Word Press这一点显而易见。我使用W3 Total Cache插件并缩小HTML、CSS和JS。我也可以使用CDN。

是否可以修改W3 Total Cache插件,以便它可以重写Wordpress目录“wp content”、“wp admin”和“wp includes”,而无需实际重命名这些目录?理想情况下,我希望能够重写W3总缓存目录,如“w3tc”

2 个回复
最合适的回答,由SO网友:Chris_O 整理而成

这在Steps to Take to Hide the Fact a Site is Using WordPress.

该问题的答案包括重命名wp内容和插件目录。如果希望重写这些目录,可以使用Roots WordPress theme 重写相对于站点根目录的目录。

<?php
if (stristr($_SERVER[\'SERVER_SOFTWARE\'], \'apache\') !== false) {
    function roots_htaccess_writable() {
        if (!is_writable(get_home_path() . \'.htaccess\')) {
            add_action(\'admin_notices\', create_function(\'\', "echo \'<div class=\\"error\\"><p>" . sprintf(__(\'Please make sure your <a href="%s">.htaccess</a> file is writeable \', \'roots\'), admin_url(\'options-permalink.php\')) . "</p></div>\';"));
        };
    }

    add_action(\'admin_init\', \'roots_htaccess_writable\');

    // Rewrites DO NOT happen for child themes
    // rewrite /wp-content/themes/roots/css/ to /css/
    // rewrite /wp-content/themes/roots/js/  to /js/
    // rewrite /wp-content/themes/roots/img/ to /js/
    // rewrite /wp-content/plugins/ to /plugins/

    function roots_flush_rewrites() {
        global $wp_rewrite;
        $wp_rewrite->flush_rules();
    }

    function roots_add_rewrites($content) {
        $theme_name = next(explode(\'/themes/\', get_stylesheet_directory()));
        global $wp_rewrite;
        $roots_new_non_wp_rules = array(
            \'css/(.*)\'      => \'wp-content/themes/\'. $theme_name . \'/css/$1\',
            \'js/(.*)\'       => \'wp-content/themes/\'. $theme_name . \'/js/$1\',
            \'img/(.*)\'      => \'wp-content/themes/\'. $theme_name . \'/img/$1\',
            \'plugins/(.*)\'  => \'wp-content/plugins/$1\'
        );
        $wp_rewrite->non_wp_rules += $roots_new_non_wp_rules;
    }

    add_action(\'admin_init\', \'roots_flush_rewrites\');

    function roots_clean_assets($content) {
        $theme_name = next(explode(\'/themes/\', $content));
        $current_path = \'/wp-content/themes/\' . $theme_name;
        $new_path = \'\';
        $content = str_replace($current_path, $new_path, $content);
        return $content;
    }

    function roots_clean_plugins($content) {
        $current_path = \'/wp-content/plugins\';
        $new_path = \'/plugins\';
        $content = str_replace($current_path, $new_path, $content);
        return $content;
    }

    // only use clean urls if the theme isn\'t a child or an MU (Network) install
    if (!is_multisite() && !is_child_theme()) {
        add_action(\'generate_rewrite_rules\', \'roots_add_rewrites\');
        if (!is_admin()) { 
            add_filter(\'plugins_url\', \'roots_clean_plugins\');
            add_filter(\'bloginfo\', \'roots_clean_assets\');
            add_filter(\'stylesheet_directory_uri\', \'roots_clean_assets\');
            add_filter(\'template_directory_uri\', \'roots_clean_assets\');
        }
    }

    function roots_add_h5bp_htaccess($rules) {
        global $wp_filesystem;

        if (!defined(\'FS_METHOD\')) define(\'FS_METHOD\', \'direct\');
        if (is_null($wp_filesystem)) WP_Filesystem(array(), ABSPATH);

        if (!defined(\'WP_CONTENT_DIR\'))
        define(\'WP_CONTENT_DIR\', ABSPATH . \'wp-content\');   

        $theme_name = next(explode(\'/themes/\', get_template_directory()));
        $filename = WP_CONTENT_DIR . \'/themes/\' . $theme_name . \'/inc/h5bp-htaccess\';

        $rules .= $wp_filesystem->get_contents($filename);

        return $rules;
    }

    add_action(\'mod_rewrite_rules\', \'roots_add_h5bp_htaccess\');
}

?>
您还需要确保并删除W3 Total Cache X-Powered-by标头。

<IfModule mod_headers.c>
         Header set X-Powered-By "W3 Total Cache/0.9.2.3"
    </IfModule>
如果要使用CDN W3 Total缓存,则将使用相同的路径结构:

wp-content/w3tc/min/xxxxx/default.include.xxxx.css

因此,您需要使用重写这些。如果您有权访问或未使用minify,请访问CDN上的htaccess。

SO网友:Wyck

隐藏WordPress是可能的,但需要付出很多努力,而且更新也有问题。此外,这是一个错误的解决方案,更好的选择是切实保护WordPress,有许多指南/插件可以帮助您做到这一点。

为了回答您的问题,为了安全起见,使用w3 total cache重写目录并没有多大意义。

结束