How to prevent WordPress setup in ‘blog’ subdomain, redirecting to ‘www’ when trying to finish Installation

I have a main site http://www.example.com that’s written in another language (Ruby/Rails). I want a wordpress blog installed in http://blog.example.com. I have control over the server and DNS.

I have created the necessary CNAME record for the ‘blog’ subdomain. But after setting up apache and restarting it, when I visit http://blog.example.com, for the final installation steps, I’m redirected to http://www.example.com/wp-admin/install.php.

Read More

Also now when I try to visit the main site http://www.example.com, I’m being redirected to the above wordpress install page.

How can I make it work like this: the blog should only reside in blog.example.com path, and the main site should be accessible via http://www.example.com.

Removing the www subdomain is not an option as it’s been like that for awhile for the main site. It might be ok, if somehow a redirect can be setup from www to non-www url, though I’m not aware how to set it up.

Please suggest.

Here’s the main site’s apache conf:

     <VirtualHost *:80>
ProxyPreserveHost On
ServerAdmin webmaster@localhost
ServerName http://www.example.com
ServerAlias example.com

DocumentRoot /home/apps/example/current/public
<Directory /home/apps/example/current/public>
AllowOverride all
Options -MultiViews
</Directory>
#RewriteEngine On
#Redirect / http://example.com/
</VirtualHost> 

Here’s the apache conf for the wordpress under ‘blog’ subdomain:

     <VirtualHost *:80>
ServerName blog.example.com
ServerAlias blog.example.com

ServerAdmin webmaster@localhost
DocumentRoot /home/apps/example_blog/wordpress_blog
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

<Directory /home/apps/example_blog/wordpress_blog>
AllowOverride All
</Directory>

</VirtualHost> 

Related posts

3 comments

  1. WordPress has domain references in the database and the code which will throw your permalinks off and cause bad redirects. These renegade URLs should appear as 404’s on your root domain (example.com). If not I’d double check the root domain with the sub domain removed from the vhosts.

    I don’t see any issues with your current vhost configuration. I would also try testing the domains in isolation if you suspect its vhost related. I suspect its a WordPress site url issue.

    Assuming the database records are incorrect.

    1. Log into phpMyAdmin or other database manager.
    2. Select your WP database.
    3. Go into the wp_options table (wp_ prefix may be different).
    4. Look for the record’s with option name = “siteurl” & “home”.
    5. Edit these records to reflect your new domain name.

    Here’s the WordPress documentation on how to switch a sites urls schema.

    Document

  2. Your problem is likely deep in various DB references throughout your WP project. I’ve run into this problem deploying WP before. You’ll need to edit the DB directly to fix the issues.

    1. Export your WordPress DB with phpMyAdmin or SequelPro (something that gets you a clean .sql file)
    2. Use a text editor like Sublime or Atom, search for “www.example.com” and replace all with “blog.example.com” then save.
    3. Upload DB to prod location and you should see these errors go away.
  3. This should not happen if your virtual host is configured correctly
    but still as your tables are not created so you can only do one try with this step :

    you can add in your wp-config.php file the following parameter

    define(‘wp_site_domain’, ‘blog.example.com’);

    This will force the wordpress to follow blog.example.com

Comments are closed.