一、修改网站根目录 可以提前在网站后台修改网站地址,也可以在wp-config.php中添加、修改如下代码,Swartz为二级目录:

if ( defined( 'WP_CLI' ) ) {
    $_SERVER['HTTP_HOST'] = 'localhost';
}

define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/Swartz');
define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] . '/Swartz');

二、修改网站伪静态

1、Nginx

#  Wordpress 搭建在二级目录
rewrite ^.*/files/(.*)$ /wp-includes/ms-files.php?file=$1 last;
if (!-e $request_filename){
    rewrite ^.+?(/wp-.*) $1 last;
    rewrite ^.+?(/.*\.php)$ $1 last;
    rewrite ^ /index.php last;
}

2、Apche

# Wordpress 搭建在二级目录
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /make/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /Swartz/index.php [L]
# END WordPress

“有时求而不得未必是遗憾。”