0

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.

1 Answer 1

2

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;
}
7
  • @user2924 - Did it work for you? Also since you are a new user be sure to follow up, see: wordpress.stackexchange.com/faq#howtoask Commented Mar 3, 2011 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
    Commented Mar 3, 2011 at 22:25
  • @user2924 - Doh! I forgot to add exit;. :-) Commented Mar 3, 2011 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
    Commented Mar 3, 2011 at 22:52
  • @user2924 Can you use echo and exit statements to debug the values? Maybe your setup differs from the default and my approach missed something? Commented Mar 4, 2011 at 4:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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