PHP redirect based on HTTP_HOST/SERVER_NAME within same domain -


i trying redirect specific path based on http_host or server_name php-script.

i have tried these scripts:

1.

$domain = $_server["server_name"]; if (($domain == "example.dk") ||    ($domain == "www.example.dk")) {     header("location: /index.php/da/forside");  } ?> 

2.

switch ($host) {          case 'example.dk':                 header("http/1.1 301 moved permanently");                 header("location: http://www.example.dk/index.php/da/forside/");                 exit();          case 'www.example.dk':                 header("http/1.1 301 moved permanently");                 header("location: http://www.example.dk/index.php/da/forside/");                 exit();            default:                 header("location: http://www.example.se");                 exit();                  } ?> 

and other similar scripts. either page loads forever or browser returns redirection error.

ok, how 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 need request_uri field, otherwise wouldn't work.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -