A: 

The most common redirection error is a redirection loop.

  1. Does the script really end after your first example?
  2. Where does $host come from?

Also, SERVER_NAME is usually an apache configured global name, HTTP_HOST is really the right way to do this.

HTTP_HOST may contain the port number, keep this in mind.

So what's the url of your script, and where are you redirecting to?

A simple way to debug is to echo the contents of HTTP_HOST and instead of calling header(), also call 'echo'.

Evert
A: 

Because your are redirecting to the same server (example.dk) and your code executes again and again in a loop.

use this code instead:

$domain = $_SERVER["SERVER_NAME"];
if (($domain == "example.dk" ||
   $domain == "www.example.dk") && !$_GET['redirected'])  { 
   header("location: /index.php/da/forside?redirected=1"); 
}
rahim asgari
**The PHP Documentation says:** `HTTP/1.1 requires an absolute URI as argument to » Location: including the scheme, hostname and absolute path, but some clients accept relative URIs.` So it's better to have an absolute URI in your example.
Nirmal
It worked, but when I click on anything on that page, I can't surf nowhere. I am just stuck on that page. Also, will this be search engine friendly?
nctrnl
@nctrnl what are your other pages urls?
rahim asgari
@rahim asgari like this: http://example.dk/index.php/da/axe, http://example.dk/index.php/da/sword, etc
nctrnl
they are in example.dk domain too. so they will redirect to /index.php/da/forside too.
rahim asgari
Is it possible to make like "ends with example.dk", so that it doesn't make this redirect thingy when I'm trying to visit links on the same domain?
nctrnl
A: 

Ok, this is how I solved it:

<?php
$domain = $_SERVER["SERVER_NAME"];
$requri = $_SERVER['REQUEST_URI'];
if (($domain == "www.example.dk" && $requri == "/index.php"  ||
   $domain == "example.dk") )  { 
   Header( "HTTP/1.1 301 Moved Permanently" ); 
   header("location: http://www.example.dk/index.php/da/forside"); 
}

else if (($domain == "uk.example.dk" && $requri == "/index.php"  ||
   $domain == "www.uk.example.dk") )  {
   Header( "HTTP/1.1 301 Moved Permanently" );    
   header("location: http://uk.example.dk/index.php/en/uk/home"); 
}

else if (($domain == "www.example.se" && $requri == "/index.php"  ||
   $domain == "example.se") )  { 
   Header( "HTTP/1.1 301 Moved Permanently" ); 
   header("location: http://example.se/index.php/sv/hem"); 
}

?>

It appears I need the REQUEST_URI field, otherwise it wouldn't work.

nctrnl