Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 2017974
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T09:01:22+00:00 2026-05-17T09:01:22+00:00

I am trying to redirect to a specific path based on HTTP_HOST or SERVER_NAME

  • 0

I am trying to redirect to a specific path based on HTTP_HOST or SERVER_NAME with a 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 the page loads forever or the browser returns some redirection error.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T09:01:24+00:00Added an answer on May 17, 2026 at 9:01 am

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I am trying to redirect from http://www.domain.com/prod.php?id=23 To http://www.domain.com/index.php?q=35 I tried something like
I'm trying to redirect a few pages to a new domain and I have
I'm trying to redirect all the webpages from certain domain names to a specific
I am trying to redirect traffic coming from a specific domain inside my .htaccess
I'm trying to redirect to a .php page if the $validForm variable is TRUE.
I have a custom registration form. I am trying to redirect users to a
I have a problem with a redirect I am trying to do from within
I'm trying to redirect pages from several old domains on one new domain on
I am trying to redirect all .cfm pages on my server to a specific
I am trying to redirect any calls to a specific file extension (here .jphp)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.