泛域名绑定到wordpress网站二级目录

要将WordPress的泛域名绑定到二级目录,你需要在你的服务器上修改Apache或Nginx配置文件。以下是两种最常见的服务器配置的示例:

Apache服务器

编辑你的虚拟主机配置文件,通常位于/etc/apache2/sites-available/目录下。

<VirtualHost *:80>
    ServerAdmin webmaster@yourdomain.com
    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服务器

编辑你的站点配置文件,通常位于/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为你的实际域名和网站根目录,以及/subdirectory/为你的二级目录。

注意:在进行这些更改之前,请确保备份你的配置文件,并在完成后检查配置是否正确,以防止服务中断。同时,确保你的WordPress网站配置文件(wp-config.php)中已经正确设置了WP_HOME和WP_SITEURL常量,以反映新的域名结构。

原文

https://www.jianzhanpress.com/?p=7212

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值