Mobile app version of vmapp.org
Login or Join
Shelley277

: 301 redirecting when swapping subdomains 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.

@Shelley277

Posted in: #301Redirect #Redirects

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:


Redirect original example.com posts to apps.example.com
Redirect original community.example.com posts to example.com
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?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Shelley277

1 Comments

Sorted by latest first Latest Oldest Best

 

@Ann8826881

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 ^/?(.*) example.com/ [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: apps.example.com'.$_SERVER['REQUEST'],true,302);

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

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme