Redirect FB visitors to another domain

I'm using http://mysite.org for facebook and i have seen that people use multiple domains because of reach problem, I would like that to assign http://other.com to create links and share as http://other.com on facebook but when user clicks link they come to http://mysite.org post.

Would that be possible?

  • Adam Czajczyk

    Hello Scooper,

    I hope you're well today and thank you for your question!

    Let me please make sure that we're on a same side :slight_smile: If I understand you correctly, you'd like to use two domains at once for your site and then use "other.com" for links shared on FB but those links should then be redirected to the same content but on "mysite.org" domain. Is that right?

    I think this could be done in several ways (though not extremely "click and done" way). I'd like to ask you though which way would you prefer as I can see two options here:

    1. The link to /my-super-article is shared as a "http://other.com/my-super-article" and then when user visits it he/she is taken to "http://mysite.org/my-super-article"

    2. The "other.com" acts as an "URL shortener " (you private one) and "/my-super-article" is shared as e.g. "http://other.com/rpxs7wd" which then takes visitor to "http://mysite.org/my-super-article"

    Does it make sens to you or am I missing something here?

    Please advise!
    Best regards,
    Adam

  • Adam Czajczyk

    Hello Sam,

    Thank you for your replay!

    I think there may be a simple workaround here, assuming you're using a regular single WordPress install (not a Multisite). The idea is to setup an additional site.

    You're main site would be available under the "mydomain.com" domain. You could then setup a basic WordPress (separate install) under the "other.com" domain. Make sure that you set the permalink structure to be exactly the same as on your "mydomain.com" and that you set the site's "Search Engine Visibility" option to "Discourage search engines from indexing this site" (in order to avoid "duplicate content" and decreasing mydomain.com search rank).

    The next step would be to install our Autoblog plugin on the "other.com" site:
    https://premium.wpmudev.org/project/autoblog/

    This plugin reads specified RSS feed and publishes it as posts to the site. Therefore you could configure it to use RSS feed from your "mydomain.com". As a result you'd be able to share article on FB directly from "other.com" site. Make sure that the theme you set for "other.com" supports FB OpenGraph tags though.

    The last bit here would be to redirect visitors to the "mydomain.com". This can be done with a HTTP 301 (permanent) or 302 (temporary) redirect and the trick is to exclude Facebook crawler from that redirect. Crawler's that you will want to exclude from redirect are listed here:

    https://developers.facebook.com/docs/sharing/webmasters/crawler#identify

    Best regards,
    Adam

  • Adam Czajczyk

    Hello Scooper!

    i have seen some plugins like multidomain, multi domain with analytic but i am not really smart to know hot to use them

    This may be a solution but I never tested those plugins except our own Multi-Domains plugin. It will not do the trick here though as it's meant to work only with Multisite WP installs and its main purpose is to give sub-site admins a choice under which of available domains they'd like to setup their site.

    I can however see the main down-side of any "multi-domain" solution here. The general idea is to make your site available under multiple-domains at once and I suppose making Facebook crawlers to use the one that you chose may require quite a bit of custom coding.

    Thank you very much for this but i am having one issue here all the links have to redirect 1 by 1 and also how do i remove facebook crawler i am not getting that and is this the only method for this?

    This is actually suggested by Facebook in their docs for developers. They suggest user-agent strings that should be excluded. I think this would be doable with some custom PHP code that should be added to a header of the "other.com" site. We could make use of MU Plugin ("Must Use" plugin) here. This should do the trick I think:

    <?php
    function wpmu_no_fb_redirect() {
    
    	/* excluded USER AGENT strings */
    	$ex_ua = array('facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)','facebookexternalhit/1.1','Facebot');
    	/* domain definitions */
    	$fb_domain = 'other.com'; // this is the domain visible for FB only
    	$main_domain = 'main.com'; // this is the "real" domain
    
    	$ua = $_SERVER['HTTP_USER_AGENT'];
    	$actual_link = "http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
    	if (!in_array($ua,$ex_ua)) {
    		// if detected user agent is not in excluded user agents list
    		// let's replace fb_domain with main_domain and make redirect
    		$actual_link = str_ireplace($fb_domain,$main_domain,$actual_link);
    		header("HTTP/1.1 301 Moved Permanently");
    		header("Location: ".$actual_link);
    
    	}
    }
    
    add_action('wp_head','wpmu_no_fb_redirect',1);

    To give it a try on your site, please first create an empty file with a .php extension (e.g. "no-fb-redirect.php") and then adjust following lines:

    $actual_link = "http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";

    As you can see the value here starts with "http://". If you main site is using https:// instead, make that "https://"

    $fb_domain = 'other.com'; // this is the domain visible for FB only
    	$main_domain = 'main.com'; // this is the "real" domain

    The first line is the domain name (please note no "http" or "https" prefix!) of your "FB only" site . The second one is the domain name of your "live" (real) site to which everything except Facebook crawlers should be redirected.

    Once these adjustments are made, please access you "other.com" (Facebook only) site install via FTP and upload the file to the "/wp-content/mu-plugins" folder. If there's no "mu-plugins" folder inside "/wp-content", please create it.

    Best regards,
    Adam

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.