1

I want to setup a single wordpress install to allow users to visit using 2 domains:

For example:

foo.com

bar.foo.com

I can do this for the most part, but whatever domain is configured in the wp-admin screen, it will redirect to that whenever any of the links are clicked.

For example, if I set it up to foo.com and I come in using bar.foo.com and click an article link, it takes me to foo.com and the article link. I want the user to stay on the domain they came in.

HBruijn
  • 77,029
  • 24
  • 135
  • 201
Joelio
  • 177
  • 2
  • 15

3 Answers3

1

It depends. Do you want one domain to redirect to the other, or do you want the same content available on both domains?

For the former, just use a rewrite rule to permanently redirect the first domain to the second domain. It's important that you use a permanent redirect (301) or Google will penalize you for duplicate content:

RewriteCond %{HTTP_HOST} ^myfirstdomain\.com$
RewriteRule (.*) http://myseconddomain.com$1

The latter is much harder because WordPress expects a "main" domain for each blog, and it's not something you would want to do for SEO reasons because Google will see two pages that are exactly the same in two different spots.


You can map multiple domains to the same blog but WordPress will always redirect them to the primary domain.

You can proxy the requests from bar.foo.com to foo.com (just don't map bar.foo.com in WordPress):

RewriteCond %{HTTP_HOST} ^myfirstdomain\.com$ RewriteRule (.*) http://myseconddomain.com$1 [P,L]

I've never tried this so it might not work without problems. Either way, it's a really bad idea to do this for so many reasons.

1

Well, I tried rewriting above and it didnt work so well, but this seemed to work pretty well:

Go to plugins folder and create a file with this in it:

<?php
/*
Plugin Name: Disable Canonical URL Redirection
Description: Disables the "Canonical URL Redirect" features of WordPress 2.3 and above.
Version: 1.0
Author: Mark Jaquith
Author URI: http://markjaquith.com/
*/

remove_filter('template_redirect', 'redirect_canonical');

?>

Enable the plugin, then wala, it works!

YeahStu
  • 113
  • 1
  • 5
Joelio
  • 177
  • 2
  • 15
0

No coding necessary! Simple install http://wordpress.org/extend/plugins/domain-theme/ and everything (domains and subdomains and different theme options per domain) are taken care of! Enjoy!