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 8864361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:13:22+00:00 2026-06-14T16:13:22+00:00

trying to have a index.php file for 3 different domains… so I need to

  • 0

trying to have a index.php file for 3 different domains… so I need to display different content for the different domains. But want it to work also on “sub folders” for sub folders I mean site1.com/some_content

this is my code but it doesn’t work as I want.

<?php
    $host = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
    if($host == 'site1.com')  {
        echo "A LOT OF HTML JAVASCRIPT AND CSS";
    }
    if($host == 'site2.com')  {
        echo "Same here but different content";
    }
    if($host == 'site3.com')  {
        echo "Cats and flowers";
    }
?>

any ideas? Thanks!

  • 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-06-14T16:13:23+00:00Added an answer on June 14, 2026 at 4:13 pm

    If you are using Apache, you could define something like this in your .htaccess file:

    SetEnvIfNoCase Host "^development.example.com$" APPLICATION_ENV=development
    SetEnvIfNoCase Host "^staging.example.com$"     APPLICATION_ENV=staging
    SetEnvIfNoCase Host "^example.com$"             APPLICATION_ENV=production
    

    Then, in your index.php file (or whatever you include on every page load) add this:

    defined('APPLICATION_ENV')
        || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
    

    Afterwards, you can read the value of APPLICATION_ENV anywhere in your code to determine what environment you are on at the moment like this:

    switch (APPLICATION_ENV) {
       case 'development':
           // do stuff
           break;
    
       case 'staging':
           // do stuff
           break;
    
       case 'production':
       default:
           // do stuff
           break;
    }
    

    You can point multiple hostnames to the same IP/host in your /etc/hosts (or C:/Windows/System32/drivers/etc/hosts) file like this (assuming it’s on localhost):

    127.0.0.1 development.example.com
    127.0.0.1 staging.example.com
    127.0.0.1 example.com
    

    I know having a global constant is not idea, but it’s better than relying on HTTP_HOST as that can easily be changed.

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

Sidebar

Related Questions

I'm trying to develop a Facebook application, and I have uploaded my index.php file,
Trying to use JSTL but have the following problem: Index.xhtml page: <?xml version=1.0 encoding=UTF-8?>
I have few import statements in my index.php file. The website is bit slow
Ok I have a script in the folder 'intake'. The index.php file auto creates
I have an index.php file that I would like to run getdata.php every 5
I am trying to create a single php file I can use to display
I have a PHP file at my server root .. index.php .. which include
I am trying to have an element index view displaying the associated projectname (
I have a lucene index I am trying to do a wildcard search. In
I have an existing index with some documents I'm trying to search. When I

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.