0

I have two domain names: themaindomain.com and thealias.com. Wordpress is located under themaindomain.com.

I was wondering if it is possible to change the urls to posts and pages when there is a request from thealias.com To make clear: When there is a request from themaindomain.com, the server returns a page with some links like themaindomain.com/post1, themaindomain.com/page1. When there is a request from thealias.com, the server should return a page with some other links like thealias.com/post1, thealias.com/page1. So the two domains point to the same blog, but depending on the request url it changes the links.

Is this possible and if it is, how?

Thanks a lot...

1 Answer 1

2

You can use the the WP_HOME directive in your wp-config.php. Just set it dynamically based on $_SERVER['HTTP_HOST'] like the example in the codex.

<?php
define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']);

You might also want to define WP_SITEURL in the same way. I do something like the above for the wp-content url on one of my sites:

<?php
define('WP_CONTENT_URL', '//' . $_SERVER['HTTP_HOST'] . '/content');

All that said, the SEO in me is screaming that this is a terrible idea -- duplicate content and such. Much better to have a single site and redirect the alias to the canonical site.

3
  • About that SEO, you're right, I guess. I haven't thought that much about it. Thank you anyway.
    – Ties
    Commented Jul 18, 2012 at 21:25
  • @chrisguitarguy Thank you for this! I found it today when I was searching for a way to change the URL for aliases in WordPress itself instead of htaccess. But I added s to get https:// instead, since your answer was in 2012 and now https is more common. Anyway, you mentioned it was bad in terms of SEO, could you please elaborate on that? Is it bad for all websites or just those that have specific marketing needs?
    – jsmod
    Commented Apr 11, 2019 at 16:11
  • You generally want to have exactly one URL at which content lives or you'll get penalized for duplicate content. Stuff like rel="conical" links can help with this. Commented Apr 11, 2019 at 21:09

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.