将wordpress网站切换到ubuntu服务器上的另一个域

时间:2019-06-25 19:11:58

标签: wordpress

我有一个带有apache的ubuntu服务器,我创建了一个WordPress网站,我想将其切换到另一个域。我的网站名称为siteA,我想称之为siteB。对网站配置文件进行更改是否足够,并且在wordpress中,我更改了WordPress中的永久链接,我是否必须更改wp-config还是可以保留它?

<VirtualHost *:80>
        ServerName siteA.com
        ServerAlias siteA.com *.siteA.com siteB.com *.siteB.com
        <Directory /var/www/siteA>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Require all granted
        </Directory>

        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/siteA

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
RewriteEngine on
RewriteCond %{SERVER_NAME} =*.siteA.co.za [OR]
RewriteCond %{SERVER_NAME} =siteA.co.za
RewriteCond %{SERVER_NAME} =*.siteB.co.za [OR]
RewriteCond %{SERVER_NAME} =siteB.co.za
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

1 个答案:

答案 0 :(得分:0)

为避免重定向问题,您应该
a)更新wp-options表并调整homesiteurl
b)在wp-config.php中定义您的新域:

define( 'WP_HOME', 'http://example.com' );
define( 'WP_SITEURL', 'http://example.com' ); 

请注意,在wp-config中定义常量将覆盖数据库中的home / siteurl设置。

重建永久链接后,您的帖子和文件附件应能按预期解析。 请注意,某些插件未遵循最佳做法。即与其存储诸如[attachmentid=2]之类的简码,不如直接在WYSIWYG编辑器中嵌入绝对路径的字符串。

我建议使用此工具: https://interconnectit.com/products/search-and-replace-for-wordpress-databases/

...这将进行可靠的搜索,并在数据库中替换硬编码的路径字符串。

提示,您的浏览器可能会缓存DNS解析。如果您已按照这些步骤操作,并且在尝试登录时仍然遇到重定向问题,请尝试将虚拟GET参数附加到新URL,例如?dummy = wqwehb