WordPress 優化 wp-config.php 編輯
//1.(這裡是單行 PHP 註解) 取消檔案上傳限制
define('ALLOW_UNFILTERED_UPLOADS', true);
//2.停用 WordPress 裡文章版本的功能與3.擇1
//define( 'WP_POST_REVISIONS', false);
//3.保留文章版本功能,限制資料庫裡的修訂數3 為要保留的文章版本數量與2.擇1
define( 'WP_POST_REVISIONS', 3);
//4.變更文章自動儲存的時間間隔單位'秒'
define( 'AUTOSAVE_INTERVAL', 120 );
//5.停用 WordPress 內的佈景主題編輯器
define( 'DISALLOW_FILE_EDIT', true );
佈景主題編輯器 functions.php 內優化
//移除不必要 meta-data 標籤
remove_action( 'wp_head', 'wp_generator' ) ; remove_action( 'wp_head', 'wlwmanifest_link' ) ; remove_action( 'wp_head', 'rsd_link' ) ;
//停用 WordPress 迴響的 HTML 功能
add_filter( 'pre_comment_content', 'wp_specialchars' );
//隱藏 WordPress Feeds 網址,宣傳主要 RSS Feeds
remove_action( 'wp_head', 'feed_links', 2 );
remove_action( 'wp_head', 'feed_links_extra', 3 );
//隱藏 WordPress 登入畫面的錯誤訊息
function no_errors_please(){
return 'GET OFF MY LAWN !! RIGHT NOW !!';
}
add_filter( 'login_errors', 'no_errors_please' );
//停止 WordPress 猜測網址,導向 404
add_filter('redirect_canonical', 'stop_guessing');
function stop_guessing($url) {
if (is_404()) {
return false;
}
return $url;
}
//修改登入網址在網址後打入wp-login.php?login=leojsp 才能到達登入網頁
add_action('login_enqueue_scripts','login_protection');
function login_protection(){
if($_GET['login'] != 'leojsp')header('Location: https://www.leojsp.kozow.com/404');
}
WordPress根目錄底下的.htaccess 檔案
Options All -Indexes
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
#保護 .htaccess
order allow,deny
deny from all
satisfy all
#保護 WP-Config.php
order allow,deny
deny from all
#保護 /Wp-Content/
Order deny,allow
Deny from all
Allow from all
#保護 Include-Only 檔案
# Block the include-only files.
RewriteEngine On
RewriteBase /
RewriteRule ^wp-admin/includes/ - [F,L]
RewriteRule !^wp-includes/ - [S=3]
RewriteRule ^wp-includes/[^/]+.php$ - [F,L]
RewriteRule ^wp-includes/js/tinymce/langs/.+.php - [F,L]
RewriteRule ^wp-includes/theme-compat/ - [F,L]
#封鎖某人進入你的網站
order allow,deny
deny from 123.1.1.2
deny from 123.1.2.3
allow from all
#允許瀏覽器快取
## EXPIRES CACHING ##
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 2 days"
## EXPIRES CACHING ##
#禁止直接連結圖片
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www.)?yourwebsite.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www.)?yourotherwebsite.com [NC]
RewriteRule .(jpg|jpeg|png|gif)$ http://i.imgur.com/g7ptdBB.png [NC,R,L]
AddDefaultCharset UTF-8