skip to Main Content

I’m using bootstrap to make a website and I noticed my php index overrides my html index. Is the php code supposed to refer part of the html code to display?

For example, I have a nice little text message that says “hey” in html. Then some random php password checker script I found online.

Nothing in my page says “hey“, it’s as if the php is the html. I’m new so maybe I’m just tripping.

Sorry if it is hard to understand.

2

Answers


  1. It sounds like you have two index pages: index.html and index.php.

    The PHP page will take precedence due to the DirectoryIndex directive of Apache:

    DirectoryIndex index.php index.html
    

    You can change this to pick .html files by default if you would like (by swapping the order so that index.html comes first), though there is no real need, as you can still write HTML from within the PHP file:

    index.php:

    <?php
    echo "<h1>hey</h1>";
    ?>
    
    <h1>hey</h1>
    

    Both approaches are valid, and both will allow you to output HTML from a PHP file.

    Login or Signup to reply.
  2. Are you using an Apache server? If so, there is a directive in there that tells it what to do when you reference a folder and not a file. It will list the file types in order of priority. For example:

    DirectoryIndex index.php index.html

    Swap index.php and index.html around and the HTML will take priority.

    You can find the directive in your Apache config file usually called httpd.conf or apache.conf.

    Alternatively, to make sure the correct file is called, just reference it explicitly in your browser eg: localhost/index.html.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search