WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have to domains: mydomain.dk and mydomain.de. Both are showing the same page in danish. I have a plugin that takes care of the languages, but I need to connect the .de domain to the german 'language layer'.

How can I redirect mydomain.de to mydomain.dk/?lang=de. The mydomain.dk must stay as it is.

Thanks in advance!

share|improve this question
which plugin do you use? WPML? – fischi May 10 '12 at 13:39

You could check the contents of the $_SERVER['REQUEST_URI'] array when the site is loaded, by placing the conditional checking logic in your header.php file of your site and then redirect the user to the appropriate language from there.

For example in header.php add:

$incomingUrl = $_SERVER['REQUEST_URI'];
if($incomingUrl == 'mydomain.dk') {
  wp_redirect(URL FOR THIS LANGUAGE);
} else {

The PHP manual page can also give you more information on the $_SERVER global array here: http://php.net/manual/en/reserved.variables.server.php

Hope this helps.

share|improve this answer
Thank you. I was looking for a simple script like this, but unfortunately I'm new to php and I am getting an error, when I add this code. Am I doing it 100% right? code $incomingUrl = $_SERVER['REQUEST_URI']; if($incomingUrl == 'mydomain.de') { wp_redirect('mydomain.dk/?lang=de'); } else { wp_redirect('mydomain.dk); } code of course I set 'mydomain' to the real domain. Where exactly do I have to place the code in the header.php. I placed it at the beginning surrounded by php-tags. Hope you can help! – Kebu May 10 '12 at 13:45
What is the error that you are getting? – Richard Grey May 10 '12 at 13:46
It in danish, but it says that the website redirects to itself. – Kebu May 10 '12 at 13:52
and therefore never finishes the request... – Kebu May 10 '12 at 13:54
You will need to place it at the top of the file, immediately after the opening php tags. It's weird that it is saying that it redirects to itself, as the point of wp_redirect() is that you can go to a different page on the same site. I have changed the else clause to an elseif like this: if($incomingUrl == 'mydomain.de') { wp_redirect('mydomain.dk/?lang=de'); exit; } elseif ($incomingUrl == 'mydomain.dk') { wp_redirect('mydomain.dk); exit; } Can you let me know if it works, and if not, copy and paste the error exactly. – Richard Grey May 10 '12 at 13:59

Your Answer


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.