2

I want to move/create some sub-domains like so:

example.com moves to apps.example.com

community.example.com moves to example.com

The apps sub-domain is new. The existing community sub-domain will no longer be needed.

I've already created the apps subdomain and moved the site that was at example.com to apps.example.com.

I've also moved the site community subdomain so it now resides at example.com.

Now I just need to figure out the best way to handle the redirects. For some reason I'm just having a tough time wrapping my mind around this and hoping for some help :)

To sum up:

  1. Redirect original example.com posts to apps.example.com
  2. Redirect original community.example.com posts to example.com
  3. And, of course, ensure that all new posts on either site are going to be found in the right place!

These are WordPress sites - and there are plugins but not sure if that's best.

What would you all recommend?

6
  • If I am there, then I will not move main domain content to sub domain, because if you don't internal link it properly, then Google might be treat your sub-domain as separate site.
    – Goyllo
    Dec 29, 2015 at 10:06
  • 2
    How many pages (that need to be redirected) were at the original example.com? Is there a unique pattern to these URLs, that is different to the new URLs (ie. originally on community)? Do you have access to the server config / VirtualHost?
    – MrWhite
    Dec 29, 2015 at 11:21
  • I've already done the move Goyllo. 80,000 pages were at the original url. Nothing unique other than the post title itself.
    – Rob50
    Dec 29, 2015 at 13:15
  • And yes, I have access on both servers. By your comments I take it this is not a simple matter of adding a redirect rule in my .htaccess file?
    – Rob50
    Dec 29, 2015 at 13:16
  • You can't redirect A to B and B to C without redirecting A to C
    – symcbean
    Dec 29, 2015 at 22:38

1 Answer 1

2

Redirect original community.example.com posts to example.com

You'll still need to keep the subdomain alive in order to redirect any requests (otherwise it simply won't resolve). This is just a redirect everything. In either the .htaccess file at community.example.com or the main .htaccess file at example.com (or your server config) you can do something like the following at the top of your script (before any WordPress directives):

RewriteEngine On
RewriteCond %{HTTP_HOST} =community.example.com [NC]
RewriteCond ^/?(.*) http://example.com/$1 [R=302,L]

Change the 302 (temporary) to 301 (permanent) when you are sure it's working OK.

Redirect original example.com posts to apps.example.com

This is more tricky. You obviously can't redirect everything, because you have a new site hosted here (which you are redirecting to). And you can't do nothing, since that would be SEO suicide - assuming SEO is a priority. (Moving sites / changing domains is always going to suffer some SEO impact, but that can't be helped if the change is required.)

If you only had a limited number of pages at the original site, or there was some unique pattern to these URLs that differentiated them from the new (community) site then you could set up a bunch of redirects in the Apache config (or .htaccess file). However, with "80,000 pages" and nothing to differentiate from the new URLs, this is not possible.

What you can do is issue a redirect in your (WordPress) custom 404 document. Either by looking up the requested URL in a database (preferable), to see whether you should redirect. Or, simply redirect everything that would otherwise trigger a 404. The "problem" with redirecting everything that would ordinarily 404 is that any 404 will be seen as a 404 at apps.example.com and not example.com.

For example, to redirect everything using PHP in your custom 404 at example.com, something like:

<?php
header('Location: http://apps.example.com'.$_SERVER['REQUEST'],true,302);

Again, change 302 to 301 when you are sure it's working OK.

3
  • Thank you W3D! I understand the first part - but the second part, with the 80K posts…could you point me to more information about using a database? I was thinking along those lines - just redirecting everything that is a 404, but wouldn't that impact my SEO whereas a 301 would not? The more I think about this the more it seems trying to fix it may just not work and maybe I should just let Google sort it all out (I wasn't breaking any records with visitors to my site!) because what I need is to add "apps." in front of everything so it goes to the correct page/post, not just the correct domain.
    – Rob50
    Dec 29, 2015 at 19:58
  • "redirecting everything that is a 404, but wouldn't that impact my SEO whereas a 301 would not?" - This won't affect SEO (not doing anything will impact SEO). By using a custom 404 document you never actually return a 404 status, since you are changing it to a 301 redirect instead - the only status that is returned is the 301. I'm suggesting a "custom 404" because that's usually the easiest place to do this. You basically need to execute this code at a point that a 404 would normally occur.
    – MrWhite
    Dec 29, 2015 at 20:16
  • "using a database" - this might not be feasible with 80K URLs... you would need to populate a lookup table with all 80K URLs. When there is a 404 on example.com you do a lookup in your DB for this URL. If it exists then redirect to apps.example.com, otherwise you serve the 404 on example.com. The DB lookup only occurs at the point there is a 404, so overhead is minimal.
    – MrWhite
    Dec 29, 2015 at 20:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.