0

We've recently created a new "main website" that consolidates two older sites, and need to do some final DNS and Apache configuration work for each of the old ones. (To clarify for some, this is a small company without the resources to hire experts, and I'm trying to assist in an area that is not my specialty, and determine how these changes need to be made.)

We want to point the old sites to a folder on the new site that will "translate" the requests, as well as a couple of old subdomains pointing to new subfolders within the "translation" folders.

I've looked at related questions, but they all include considerations that are way out of my league, and are on shared hosts. Our sites are both located on EC2, so we have full control/responsibility of what gets changed.

The confusing part is a single IP being used for mulitple domains, and all of them having the same subdomains. I'm baffled as to how to insure that the primary domains are work correctly, and that the subdomains for each are still intact after everything is complete.

http://www.newsite.com   ==>  c:\www\index.php
http://subX.newsite.com  ==>  c:\www\subdomainX\index.php
http://www.oldsite.com   ==>  c:\www\oldsite\index.php
http://subX.oldsite.com  ==>  c:\www\oldsite\subdomainX\index.php

http://www.newsite.com   ==>  www.newsite.com/
http://subX.newsite.com  ==>  www.newsite.com/subdomainX/
http://www.oldsite.com   ==>  www.newsite.com/oldsite/
http://subX.oldsite.com  ==>  www.newsite.com/oldsite/subdomainX/

Oldsite http.conf (that is being shut down)

<VirtualHost *:80>
  ServerName oldsite.com
  DocumentRoot "c:/apache/htdocs/hosted/oldsite"
  ServerAlias *.oldsite.com 10.20.30.40
  RewriteEngine On
  RewriteOptions Inherit
</VirtualHost>

<VirtualHost *:80>
  ServerName subX.oldsite.com
  DocumentRoot "c:/apache/htdocs/hosted/oldsite/subX"
  RewriteEngine On
  RewriteOptions Inherit
</VirtualHost>

NEW http.conf (That is currently working in production)

<VirtualHost *:80>
  ServerName subX.newsite.com
  DocumentRoot "C:/www/subX"
  RewriteEngine Off
</VirtualHost>

What I'm trying to accomplish:, but seeking guidance/clarity on correctness:

For http://www.oldsite.com ==> c:\www\oldsite\index.php

<VirtualHost *:80>
    ???????????
    ServerName oldsite.com
    DocumentRoot "c:/www/oldsite"
</VirtualHost>

For http://subX.oldsite.com ==> c:\www\oldsite\subdomainX\index.php

<VirtualHost *:80>
    ???????????
    ServerName subX.oldsite.com
    DocumentRoot "c:/www/oldsite/subX"
</VirtualHost>

I think the DNS changes are no different, other than the new IP address, but I have no idea how to approach the Apache setup to accomodate the shared subdomains.

Update

We're retiring the old domain, so when someone goes to www.oldsite.com or sub1.oldsite.com, we want a permanent redirect to the appropriate folder in www.newsite.com. From there, the index.php contained within the folder will do the work. A url like www.oldsite.com/somewhere will be handled by www.newsite.com/oldsite/index.php.

Can someone guide me through this? I'm trying to figure out WHAT to setup to test, and as soon as I click "save", all hell is going to break loose if it's not correct. My DNS/Apache skills are iffy at best, and this is a production environment, so I can't afford to risk the down time of my typical learning curve, lol.

GDP
  • 135
  • 1
  • 6
  • 1
    Honestly the first thing to do is to create a test environment. It's not hard at all, install Apache on any other computer and copy the configuration there (For now, you don't need to copy the whole site, just making the folders with an index.html that says "hi this is oldsite.com" or "hi this is newsite.com" etc.) Edit your computer's [hosts file](https://support.rackspace.com/how-to/modify-your-hosts-file/) to override oldsite.com, www.oldsite.com, subx.oldsite.com, etc to that computer's IP and access the site from a browser on that pc. – DerfK Jan 09 '17 at 19:05
  • @DerfK , firstly THANKS for that....first time in awhile I haven't been chastised for not understanding this stuff. Secondly...in your estimation, would you say my "proposed" Virtualhost stuff looks close to correct? - I don't know what I don't know to begin. – GDP Jan 09 '17 at 19:24
  • That's going to depend on what you're *really* trying to do. If you want users to stay on subX.oldsite.com and just see content from the new directory then changing the DocumentRoot should be enough. If you want to redirect users from `subX.oldsite.com` to `www.newsite.com/oldsite/subX/` then no, you'll need something like `RedirectPermanent / http://www.newsite.com/oldsite/subX/` in the subX.oldsite.com VirtualHost block. (What if someone goes to `subX.oldsite.com/somewhere/`?) – DerfK Jan 09 '17 at 20:28
  • @DerfK , i'ts a permanent redirect to an index.php that will do all the work. We're retiring the old domains that are being merged. i've added an update to the question. – GDP Jan 09 '17 at 20:52

1 Answers1

2

I strongly, strongly recommend setting up a test server (also, backups. Definitely backups). Aside from the virtualhost configuration itself, moving applications to a new home requires testing the entire stack (does the correct PHP get executed, does the PHP connect to the correct database, etc). Either install an identical server stack on a local windows PC or ideally pay a few bucks to start a new instance of your Amazon image with a different public IP address (I don't use Windows on Amazon so I'm not sure how you do this but this question looks like it might be a starting point for getting a copy of your current instance).

Either way, to access the test system for this purpose, instead of making changes to DNS now you would edit your hosts file to override DNS on one local computer to resolve all of your hostnames to the test server's IP. This is so that you can test using the actual hostnames (rather than "test.newsite.com"), since Apache checks the hostname entered in the browser and sent in the Host: request header against the ServerName and ServerAlias directives to decide which VirtualHost block to use. You would add a single line with all of the hostnames:

1.2.3.4 oldsite.com www.oldsite.com sub.oldsite.com www.newsite.com newsite.com etc

As for the configuration, the existing newsite configuration should work as-is. You will want to make this the first VirtualHost block so Apache uses it as the default. For all of the oldsites, to redirect all the requests to a given hostname to a single URL, you can use a VirtualHost block containing RedirectPermanent / (which redirects every request starting with /, which they all do):

<VirtualHost *:80>
  ServerName old_hostname
  RedirectPermanent / http://new_hostname/oldsite/index.php
</VirtualHost>

ServerName and ServerAlias should match what you had before, but I would remove the IP address from the ServerAlias in the event that some really awful client that doesn't obey HTTP 1.1 gets stuck in a redirect loop requesting the IP over and over.

You will need to be sure that you have mod_alias enabled on your server to use the Redirect commands.

Once you have a known-good Apache configuration, use it to configure the newsite.com server (keep a backup of the previous configuration just in case). You can shut down the test server now, and edit your hosts file again and remove the line you created so you can double-check that your new server is serving newsite.com correctly, including that all of the newsite.com/oldsite/index.php pages are working correctly when you enter the URL directly. Then you can edit your host file again and enter the new server IP with all of the oldsite hostnames, and then test that the new server is redirecting the oldsite.com sites correctly.

Finally, you'll edit the DNS configuration for oldsite.com to replace the old IP address with the new one. (Now is the time to realize that you need to know what to do with email@oldsite.com if it wasn't being hosted somewhere else) Take note of the TTL settings since the old server will keep getting requests until everyone's caches expire so you won't be able to shut it down for at least that long.

DerfK
  • 19,493
  • 2
  • 38
  • 54