問題描述

我有一個網站,我們正在試圖謹慎使用我們使用 WordPress 的事實。我們可以採取甚麼措施使其不那麼明顯?

最佳解決方案

最大的 WordPress 贈品在<head> </head> 標籤之間。

由 Twentyten 主題輸出的 WordPress 主題內容示例以及如何刪除:

<link rel="profile" href="http://gmpg.org/xfn/11" />

直接從 header.php 中刪除

 <link rel="stylesheet" type="text/css" media="all" href="http://example.com/wp-content/themes/twentyten/style.css" />

透過從另一個位置呼叫樣式表來隱藏 WordPress,並更改 wp-content 目錄。 WordPress 要求您的主題在 style.css 的頂部包含一些基本資訊 (style.css 必須在主題根目錄中) 。您將需要建立一個備用的 CSS,並從頭部呼叫它。 WordPress 不需要您使用主題 style.css 它只需要它在主題目錄。

 

直接從 header.php 中刪除

<link rel="alternate" type="application/rss+xml" title="Example Blog &raquo; Feed" href="http://example.com/feed/" />
<link rel="alternate" type="application/rss+xml" title="Example Blog &raquo; Comments Feed" href="http://example.com/comments/feed/" />
<link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://example.com/xmlrpc.php?rsd" />
<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="http://example.com/wp-includes/wlwmanifest.xml" />
<link rel='index' title='Example Blog' href='http://example.com/' />
<meta name="generator" content="WordPress 3.1-alpha" />

要刪除這些額外的連結,您可以向 functions.php 新增一個過濾器

// remove junk from head
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wp_generator');
remove_action('wp_head', 'feed_links', 2);
remove_action('wp_head', 'index_rel_link');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'feed_links_extra', 3);
remove_action('wp_head', 'start_post_rel_link', 10, 0);
remove_action('wp_head', 'parent_post_rel_link', 10, 0);
remove_action('wp_head', 'adjacent_posts_rel_link', 10, 0);

您可以在 wp-config.php 檔案中更改外掛目錄和 wp-content 目錄,但如果您的主題或任何外掛不使用正確的方法來呼叫檔案,則可能會遇到一些問題。

define( 'WP_CONTENT_DIR', $_SERVER['DOCUMENT_ROOT'] . '/new-wp-content' );

將 WP_CONTENT_URL 設定為此目錄的完整 URI(無拖尾斜槓),例如

define( 'WP_CONTENT_URL', 'http://example/new-wp-content');

可選將 WP_PLUGIN_DIR 設定為此目錄的完整本地路徑 (無字尾斜槓),例如

define( 'WP_PLUGIN_DIR', $_SERVER['DOCUMENT_ROOT'] . '/new-wp-content/new-plugins' );

將 WP_PLUGIN_URL 設定為此目錄的完整 URI(無拖尾斜槓),例如

define( 'WP_PLUGIN_URL', 'http://example/new-wp-content/new-plugins');

PLUGINS

請注意,像 Akismat,All in One SEO,W3-Total-Cache,超級快取等許多外掛會向 HTML 輸出新增註釋。大多數都易於修改以刪除評論,但隨著外掛的更新,您的更改將被覆蓋。

wp-includes

wp-includes 目錄包含 jquery 和各種其他 js 檔案,主題或外掛將使用 wp_enqueue_script() 呼叫。要改變這一點,您將需要登出預設的 WordPress 指令碼並註冊新的位置。新增到 functions.php:

function my_init() {
    if (!is_admin()) {
        // comment out the next two lines to load the local copy of jQuery
        wp_deregister_script('jquery');
        wp_register_script('jquery', 'http://googleajax.admincdn.com/ajax/libs/jquery/1.4.2/jquery.min.js', false, '1.3.2');
        wp_enqueue_script('jquery');
    }
}
add_action('init', 'my_init');

這需要用您的主題或外掛使用的每個指令碼來完成。

次佳解決方案

經常錯過的一點 – 刪除 WordPress 根目錄中的 readme.html 。它不僅將安裝識別為 WP,還具有精確的版本。不要忘記重新更新。

相關問題:Prevent access or auto-delete readme.html, license.txt, wp-config-sample.php

第三種解決方案

我一直使用 Roots Theme method 。但是,將它應用於那些 ThemeJungle 的東西通常會很頭疼。

所以,開始玩 WP_CONTENT_*常數。我認為這是一個不那麼容易出錯的方法,這是我現在正在工作的:

  /muploads 資料夾,/tthemes 資料夾,/t/t 是活動的主題資料夾。該網站並不複雜,所以幾乎沒有資產載入…


WP_CONTENTLESS

 wp-config.php

wp-content 設定為站點的根 (/public_html/) 。

/**
 Inside WP_CONTENT, the following folders should exist:
 /languages , /mu-plugins , /plugins , /themes , /upgrade , /uploads

 The WP_CONTENT_* definitions bellow REMOVE the existence of the /wp-content folder
 and makes its contents reside in the ROOT of your site

 UTTERMOST attention is necessary when doing file maintenance activities in the server (i.e.: WP upgrades, new Webmaster...),
 as the Themes and Plugins folders are meant to be renamed to /t and /p (serious candidates for unthoughful removal)

 PLEASE note:
 - we change the Plugins folder in WP_PLUGIN_* definitions
 - the Themes folder is changed by a MustUse Plugin
   (/mu-plugins/set-extra-themes-folder.php)
 - the Uploads folder is changed in WordPress settings page
   (http://example.com/wp-admin/options-media.php)
 - the hardcode path to be used in WP_CONTENT_DIR and WP_PLUGIN_DIR can be checked using an action inside the set-extra-themes-folder Plugin (check the comments in this file)
*/
define( 'WP_CONTENT_DIR', '/www/htdocs/username/public_html' );
define( 'WP_CONTENT_URL', 'http://www.example.com' );

define( 'WP_PLUGIN_DIR', '/www/htdocs/username/public_html/p' );
define( 'WP_PLUGIN_URL', 'http://www.example.com/p' );

我已經在 [wp-hackers] – Any drawbacks in setting WP_CONTENT_DIR (and URL) to DOCUMENT_ROOT? 中詢問過,John Blackbourn1,Mike Little2 和 Otto3 對此提出建議:

1
I’ve had this structure active on a site for the last 18
months and haven’t seen any problems. As with any change to the
location of the content directory, you’ll need to double check any
plugins you add to the site don’t assume that the content directory is
at wp-content.

2
There are discussions around the net the $_SERVER['DOCUMENT_ROOT'] may be
susceptible to hacking. In which case this is extremely dangerous because
there are lots of places that require() or include() WP_CONTENT_DIR .
‘something’;

3
There are cases where the content in $_SERVER can be perfectly safe,
but for security purposes, it is better to always treat it as
untrusted data. For this specific case, hardcode the directory.


新的主題資料夾

 /mu-plugins/set-extra-themes-folder.php

由於沒有 WP_THEMES_*常量,我們需要 register_theme_directory()函式來 「註冊包含主題的目錄」 。試圖將額外的目錄設定為根,但結果很有趣 (即:它不起作用) 。

<?php
/*
    Plugin Name: Set Extra Themes Folder
    Version: 1.0
    Description: Allows the directory - http://example.com/t - to be used as an extra theme's directory
    Plugin URI: http://wordpress.stackexchange.com/questions/1507
    Author: brasofilo
    Author URI: http://rodbuaiz.com
*/


/**
 * Remove the comment from the following line to know the correct path to put in register_theme_diretory()
*/
//add_action( 'admin_head', 'brsfl_alert_directory_path' );

function brsfl_alert_directory_path()
{
    echo '<script type="text/javascript">
        alert("Directory: '.$_SERVER['DOCUMENT_ROOT'].'");
    </script>';
}


/**
 * The following will enable the directory "t" to be used as an EXTRA Themes directory
*/
register_theme_directory( '/www/htdocs/username/public_html/t' );


/**
 * De-registering default scripts in wp-includes for CDN ones
*/
add_action('init', 'brsfl_init_scripts');

function brsfl_init_scripts()
{
    if ( !is_admin() )
    {
        wp_deregister_script( 'jquery' );
        wp_deregister_script( 'swfobject' );
        wp_register_script( 'jquery', 'http://googleajax.admincdn.com/ajax/libs/jquery/1.7.1/jquery.min.js', false, '1.7.1' );
        wp_register_script( 'swfobject', 'https://googleajax.admincdn.com/ajax/libs/swfobject/2.2/swfobject.js', false, null, true );
        wp_enqueue_script( 'jquery' );
        wp_enqueue_script( 'swfobject' );
    }
}

上傳資料夾

 /wp-admin/options-media.php

而不是 http://example.com/uploads,它將是 http://example.com/m 。取消選中 Organize my uploads into... 會給資產 URL 一個無 WPF 的外觀。如果站點是即時的,則必須在資料庫中進行搜尋/替換,並且必須移動檔案。


外掛和頭部內容

請參閱本 Q& A 中的 Cris_O 答案。


Readme.html

請參閱本 Q& A 中的 Rarst 答案。


其他步驟

像往常一樣,ThemeJungle 主題可能會提示主題中的特定駭客。喜歡… TimThumb 不工作 (!!! 哈哈!!!) 。

第四種方案

您可以在一個伺服器上使用 WordPress,並從另一個伺服器上刪除內容,只包括您需要的內容。

如果您需要 RSS,您將不得不這樣做。

有效地,它就像從代理或 CDN 提供靜態頁面,但只是要提供的位。然後,您也可以使用基於 javascript 的評論系統,如 Disqus 。

真正的資源使用不足,因為這裡服務於內容的伺服器上沒有資料庫。

第五種方案

您可以建立自定義地址登入到您的部落格。透過不使用經典的 「myblog.com/wp-admin」 路徑來訪問您的儀錶板 This page 將幫助您建立隱身登入,這對安全措施也是有好處的。

所以 ppl 誰將 wp-admin 附加到你的部落格,將無法猜到:)

第六種方案

除了上述之外,您需要鎖定對各種 wp*檔案和目錄的訪問。如果有人想看看你是否正在執行 WP,他們可能會猜測你是否有 wp-settings.php,或者是否可以訪問某個目錄。返回 403 是不夠的,因為它告訴使用者資源存在; 他們只是無法訪問它。

我不是 apache 的專家,所以我問 this question 在 serverfault 上。

參考文獻

注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。