Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm a bit lost on how to handle this redirect requirement.

So far I have:

  • www.domain-B.com parked on www.domain-A.com
  • So, requests for www.domain-B.com/page1 resolve to www.domain-A.com/page1 and so on
  • So far so good

However I would like one exception to this:

  • If user requests the root of www.domain-B.com, I would like them to go to www.domain-A.com/pageX

So everything works as normal with a parked domain except when a user goes to the root url of the parked domain.

I've tried the redirect plugin for WP but when redirecting www.domain-B.com to www.domain-A.com/pageX it actually redirects www.domain-A.com to that page as well. (because its properly parked I guess!)

Thanks in advance for any advice.

share|improve this question
add comment

1 Answer

Hi @user2924:

Use the 'template_redirect' hook; put the following in your theme's 'functions.php' file:

add_action( 'template_redirect', 'yoursite_template_redirect' );
function yoursite_template_redirect() {
  if (strtolower($_SERVER['HTTP_HOST'])=='www.domain-b.com')
    wp_safe_redirect('http://www.domain-a.com/pagex'.$_SERVER['REQUEST_URI']);
    exit;
}
share|improve this answer
    
Thank you very much Mike, appreciate the help! –  user2924 Mar 3 '11 at 22:06
    
@user2924 - Did it work for you? Also since you are a new user be sure to follow up, see: wordpress.stackexchange.com/faq#howtoask –  MikeSchinkel Mar 3 '11 at 22:13
    
OK, looked like it was working but I hadn't un-istalled the plugin. So now with no redirect plugins and the code above it does not work for me. It is as if WP does not know the request is coming from domain-b as it just sits on the regular home page. Ideas? –  user2924 Mar 3 '11 at 22:25
    
@user2924 - Doh! I forgot to add exit;. :-) –  MikeSchinkel Mar 3 '11 at 22:40
    
:-) Unfortunately it either results in a blank page, or if I try alternative url formats in the function i.e. (www.doma...) (domain...) (domain....) I either get an error where the URL parsed is too long or taken to the WP admin page, not the specified redirect page....hmmmm –  user2924 Mar 3 '11 at 22:52
show 3 more comments

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.