要將WordPress的泛域名綁定到二級目錄,你需要在你的服務(wù)器上修改Apache或Nginx配置文件。以下是兩種最常見的服務(wù)器配置的示例:

Apache服務(wù)器

編輯你的虛擬主機(jī)配置文件,通常位于/etc/apache2/sites-available/目錄下。

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot /var/www/yourdomain.com/public_html
    ServerName yourdomain.com
    ServerAlias *.yourdomain.com
 
    <Directory /var/www/yourdomain.com/public_html>
        Options -Indexes +FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
        ReWriteEngine On
 
        # 將所有請求重定向到二級目錄
        ReWriteCond %{HTTP_HOST} ^([^.]+)\.yourdomain\.com$
        ReWriteRule ^(.*) /subdirectory/%1/$1 [L]
    </Directory>
</VirtualHost>

重新加載Apache配置:

sudo service apache2 reload

Nginx服務(wù)器

編輯你的站點(diǎn)配置文件,通常位于/etc/nginx/sites-available/目錄下。

server {
    listen 80;
    server_name yourdomain.com;
    root /var/www/yourdomain.com/public_html;
    index index.php index.html index.htm;
 
    location / {
        try_files $uri $uri/ =404;
    }
 
    # 處理PHP請求
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
 
    # 將所有請求重定向到二級目錄
    server {
        listen 80;
        server_name "*.yourdomain.com";
 
        location / {
            rewrite ^/(.*)$ /subdirectory/$subdomain.$domain/$1 last;
        }
    }
}

重新加載Nginx配置:

sudo service nginx reload

請確保替換wodepress.com和/var/www/wodepress.com/public_html為你的實(shí)際域名和網(wǎng)站根目錄,以及/subdirectory/為你的二級目錄。

注意:在進(jìn)行這些更改之前,請確保備份你的配置文件,并在完成后檢查配置是否正確,以防止服務(wù)中斷。同時,確保你的WordPress網(wǎng)站配置文件(wp-config.php)中已經(jīng)正確設(shè)置了WP_HOME和WP_SITEURL常量,以反映新的域名結(jié)構(gòu)。