Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

thanks Joel

share|improve this question
add comment

migrated from stackoverflow.com Jan 1 '10 at 3:14

This question came from our site for professional and enthusiast programmers.

3 Answers

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.

share|improve this answer
    
latter, dont mind the seo hit. –  Joelio Dec 31 '09 at 21:46
    
Formatting doesn't work in comments? That blows. Will repost in a separate answer. –  Foofy Jan 1 '10 at 0:29
add comment
up vote 1 down vote accepted

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!

share|improve this answer
add comment

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!

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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