admin管理员组

文章数量:1122832

I'm migrating a site that uses subdomains. I want to test the subdomain's work on my machine before fully migrating the site. So I've chosen a fake domain name for my site, given it a subdomain name, and set it up with an Apache server. The domains are:

main = www.mysite
subdomain = app.mysite

I have set my host configuration file on Windows to be the following:

# My DNS overrides
<my-aws-ip> www.mysite
<my-aws-ip> app.mysite

Where <my-aws-ip> is the IP address of the EC2 instance I'm testing on. My configuration file for my Apache server is the following:

<VirtualHost *:80>
    ServerName www.mysite
    DocumentRoot /var/www/mysite
    <Directory /var/www/mysite>
        Allowoverride All
        Require all granted
    </Directory>
    ErrorLog /var/log/httpd/mysite-error.log
    CustomLog /var/log/httpd/mysite-access.log combined
</VirtualHost>

<VirtualHost *:80>
    ServerName app.mysite
    DocumentRoot var/www/mysite_app
    <Directory /var/www/mysite_app>
        Allowoverride All
        Require all granted
    </Directory>
    ErrorLog /var/log/httpd/app_mysite-error.log
    CustomLog /var/log/httpd/app_mysite-access.log combined
</VirtualHost>

However, when I visit my site I get redirected to an actual site called . Why is this? Does WordPress automatically redirect, and how can I prevent this from happening?

I'm migrating a site that uses subdomains. I want to test the subdomain's work on my machine before fully migrating the site. So I've chosen a fake domain name for my site, given it a subdomain name, and set it up with an Apache server. The domains are:

main = www.mysite.com
subdomain = app.mysite.com

I have set my host configuration file on Windows to be the following:

# My DNS overrides
<my-aws-ip> www.mysite.com
<my-aws-ip> app.mysite.com

Where <my-aws-ip> is the IP address of the EC2 instance I'm testing on. My configuration file for my Apache server is the following:

<VirtualHost *:80>
    ServerName www.mysite.com
    DocumentRoot /var/www/mysite
    <Directory /var/www/mysite>
        Allowoverride All
        Require all granted
    </Directory>
    ErrorLog /var/log/httpd/mysite-error.log
    CustomLog /var/log/httpd/mysite-access.log combined
</VirtualHost>

<VirtualHost *:80>
    ServerName app.mysite.com
    DocumentRoot var/www/mysite_app
    <Directory /var/www/mysite_app>
        Allowoverride All
        Require all granted
    </Directory>
    ErrorLog /var/log/httpd/app_mysite-error.log
    CustomLog /var/log/httpd/app_mysite-access.log combined
</VirtualHost>

However, when I visit my site I get redirected to an actual site called https://www.mysite.com. Why is this? Does WordPress automatically redirect, and how can I prevent this from happening?

Share Improve this question asked May 25, 2024 at 15:18 ConnorConnor 1114 bronze badges 2
  • 1 Both your sites' configs are using port 80, which is the http port. You might need to set up https in the config as well, especially if your site's home and/or siteurl are set to https://www.mysite.com. – Pat J Commented May 25, 2024 at 17:41
  • 1 Thanks, Pat, I figured it out in the end. I'll post the answer shortly. – Connor Commented May 27, 2024 at 10:30
Add a comment  | 

1 Answer 1

Reset to default 1

As mentioned by Pat in the comments, my home and siteurl config values were set to https://www.mysite.com and https://app.mysite.com respectively. These values are held inside your site's database. I think you can change them through the Wordpress admin page, or you can enter your database directly and find them with the following command:

SELECT * FROM wp_options WHERE option_name = 'siteurl' OR option_name = 'home';

In my case, the protocol for siteurl and home was https not http. I believe this meant Wordpress was redirecting traffic to https://www.mysite.com, but as my virtual hosts file doesn't handle that traffic this caused a redirect to a public DNS server and gave me the incorrect site.

(Could someone with more experience please confirm if this accurate?)

To fix the issue, I altered the siteurl and the home options to use the http protocol, which can be done from within your database using the following commands:

UPDATE wp_options SET option_value = 'http://www.mysite.com' WHERE option_name = 'home';
UPDATE wp_options SET option_value = 'http://www.mysite.com' WHERE option_name = 'siteurl';

I used these commands on the databases for both my sites, and it resolved the problem.

本文标签: multisiteHow do I test my Wordpress subdomains on AWS during migration